使用 Entity Framework Core Migrations 更改主键

Ale*_*der 6 primary-key entity-framework-core entity-framework-migrations

我正在尝试通过实体框架核心迁移更改表的主键:

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

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

To change the IDENTITY property of a column, the column needs to be dropped and recreated.
Run Code Online (Sandbox Code Playgroud)

如何更新数据库?

Ale*_*der 2

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

我更改了迁移文件。

有关此的更多信息可以在这里找到: https: //thisworksonmymachine.com/2017/02/13/ef-core-the-setup-part-4/

  • 仅当还没有对主键的引用时,这才有效。 (6认同)
  • 链接似乎已经死了。请您更新您的答案以解释您所做的事情。谢谢 (2认同)
  • 链接已死。您能更新一下您的答案吗? (2认同)