EF核心代码首先在不同计算机上的迁移之间具有身份差异

问题描述 投票:0回答:1

[我们一直在进行迁移,其中包括在一台计算机上对ASP.NET标识表的更改,但当开发人员去创建迁移时不在另一台计算机上。

我们正在使用:

  • EF Core 3.1.3
  • 。NET Identity Core
  • Package Manager控制台Add-Migration <Name>
  • Visual Studio 2019 16.5.2
  • [dotnet ef报告Entity Framework Core .NET Command-line Tools 3.1.3

我们以为上次修复此问题的原因是:

  • 将我们的EF核心工具更新为相同版本
  • 将Visual Studio更新到相同版本
  • 删除所有迁移
  • 创建新的初始迁移

但是今天又出现了。在一台计算机上,Add-Migration希望对身份表进行这些更改,而另一台计算机则不:

migrationBuilder.AlterColumn<string>(
    name: "Name",
    table: "AspNetUserTokens",
    maxLength: 128,
    nullable: false,
    oldClrType: typeof(string),
    oldType: "nvarchar(450)");

migrationBuilder.AlterColumn<string>(
    name: "LoginProvider",
    table: "AspNetUserTokens",
    maxLength: 128,
    nullable: false,
    oldClrType: typeof(string),
    oldType: "nvarchar(450)");

migrationBuilder.AlterColumn<string>(
    name: "ProviderKey",
    table: "AspNetUserLogins",
    maxLength: 128,
    nullable: false,
    oldClrType: typeof(string),
    oldType: "nvarchar(450)");

migrationBuilder.AlterColumn<string>(
    name: "LoginProvider",
    table: "AspNetUserLogins",
    maxLength: 128,
    nullable: false,
    oldClrType: typeof(string),
    oldType: "nvarchar(450)");
c# entity-framework entity-framework-core ef-code-first asp.net-identity
1个回答
0
投票

我从未发现两台计算机之间的默认值如何或为何有所不同,但是我确实找到了如何在代码中覆盖它的默认值。您可以在MaxLengthForKeys中注册身份时设置Startup.cs

services.AddDefaultIdentity<ApplicationUser>(options => {
    options.SignIn.RequireConfirmedAccount = true;
    options.Stores.MaxLengthForKeys = 128;
})
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();

这里也有相关的讨论:https://github.com/dotnet/aspnetcore/issues/14503

© www.soinside.com 2019 - 2024. All rights reserved.