[我们一直在进行迁移,其中包括在一台计算机上对ASP.NET标识表的更改,但当开发人员去创建迁移时不在另一台计算机上。
我们正在使用:
Add-Migration <Name>
dotnet ef
报告Entity Framework Core .NET Command-line Tools 3.1.3
我们以为上次修复此问题的原因是:
但是今天又出现了。在一台计算机上,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)");
我从未发现两台计算机之间的默认值如何或为何有所不同,但是我确实找到了如何在代码中覆盖它的默认值。您可以在MaxLengthForKeys
中注册身份时设置Startup.cs
:
services.AddDefaultIdentity<ApplicationUser>(options => {
options.SignIn.RequireConfirmedAccount = true;
options.Stores.MaxLengthForKeys = 128;
})
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();