无法在asp.net核心[列NULL]中执行数据库迁移 [英] Unable to perform database migrations in asp.net core [Column NULL]

查看:43
本文介绍了无法在asp.net核心[列NULL]中执行数据库迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.net核心中,我试图更新模型类以将字段从iFormFile更改为字符串.IE.回应评论存储文件名而不是图像文件.

In ASP.net core, I'm trying to update a model class to change the field from an iFormFile to a string. ie. In response to a comment to store the filename instead of the image file instead.

在更新了模型类并进行了相应的更改之后,该网页提示我更新数据库/迁移.

After updating the model class and performed the changes accordingly, the webpage prompted me to update the database / migration.

首先,有人可以向我指出 迁移是什么意思 的信息吗?

Firstly, can someone point me to information on what does it mean by migrations?

第二,键入命令后,我出现以下错误

Secondly, I have the following errors below after typing the commands

dotnet ef database update 

我收到以下错误:

Cannot insert the value NULL into column 'StaffID', table 'aspnet-
newbienoob-59e13649-49be-4a5f-9365-d1b8cc6588d5.dbo.Employee'; 
column does not allow nulls. UPDATE fails.

推荐答案

感谢Temi的回复.

数据库迁移以某种方式失败.

The database migration somehow failed.

了解迁移所生成的cs文件中的up()和down()方法的作用之后.我自己修改了SQL语句.

After understanding what the up() and down() method does in the generated cs file from the migration meant. I altered the SQL statements myself.

即.

public partial class initial2 : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {

        migrationBuilder.DropColumn(
            name: "StaffID",
            table: "Employee");

        migrationBuilder.AddColumn<string>(
            name: "StaffIdentity",
            table: "Employee",
            nullable: true,
            defaultValue: "");
    }
}

基本上,我要做的是回滚所有迁移,并进行新的迁移以更新表.

Basically what I did was to rollback all the migrations and rework on a new migration to update the table.

即. dotnet ef迁移已删除

我可以从头开始从基本表中恢复.

I'm able to revert from the base table from scratch.

这篇关于无法在asp.net核心[列NULL]中执行数据库迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆