使用Entity Framework Core迁移更改主键 [英] Changing Primary Key using Entity Framework Core Migrations

查看:177
本文介绍了使用Entity Framework Core迁移更改主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过Entity Framework Core Migrations更改表的主键:

I am trying to Change the Primary key of a table via Entity Framework Core Migrations:

protected override void Up(MigrationBuilder migrationBuilder)
{
        migrationBuilder.DropPrimaryKey(
            name: "PK_Permissions",
            table: "Permissions");
}

当我尝试更新数据库时,出现以下错误消息:

When I try to update the database I get the following error message:

To change the IDENTITY property of a column, the column needs to be dropped and recreated.

如何更新数据库?

推荐答案

我找到了一个解决方案:
这似乎是EF Core 1.1中的错误

I have found a solution: This seems to be a bug in EF Core 1.1

我更改了迁移

有关此信息的更多信息,请参见: https://thisworksonmymachine.com/2017/02/13/ef-core-the-setup-part-4/

More Information about this can be found here: https://thisworksonmymachine.com/2017/02/13/ef-core-the-setup-part-4/

这篇关于使用Entity Framework Core迁移更改主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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