执行迁移EF core 2.0时出错,将Identity id从string更改为int

zol*_*y13 7 migration identity ef-migrations entity-framework-core asp.net-core-mvc

场景:

我从同事那里收到了ASP.NET CORE中的自动生成项目.帐户/管理服务有自动生成的代码.此代码包括ApplicationUser Class,DBContext和迁移文件夹,其中包含00000000000000_CreateIdentitySchema.cs和20180323155805_Snapshot.cs.我一直在尝试将我的User类更改为具有整数id.为此,我在IdentityUser中添加了泛型:

public class ApplicationUser : IdentityUser**<int>**
{
}
Run Code Online (Sandbox Code Playgroud)

我还必须创建ApplicationRole类,因为它在迁移文件中创建之前.

public class ApplicationRole : IdentityRole<int>
{
}
Run Code Online (Sandbox Code Playgroud)

我也改变了我的背景:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser, 
    **ApplicationRole, int**>
Run Code Online (Sandbox Code Playgroud)

在迁移文件中,创建了登录方案.添加更改后,我添加了新的迁移.在添加迁移期间,我收到此错误:

要更改列的IDENTITY属性,需要删除并重新创建列.

bri*_*lam 6

您需要更新生成的迁移,以逐步进行。用AlterColumn以下操作替换呼叫:

  1. 用临时名称添加新列
  2. 删除原始列
  3. 使用原始列名重命名新列

您可能还必须重建(删除并重新创建)所有引用该列的约束。

这并非微不足道,这就是EF当前不处理它的原因。功能请求#329与更新EF以便自动处理有关。