Reputation: 1430
We keep getting migrations that include changes to the ASP.NET Identity tables on one computer, but not on the other when a developer goes to create a migration.
We're using:
Add-Migration <Name>
dotnet ef
reports Entity Framework Core .NET Command-line Tools 3.1.3
We thought we had this fixed last time it started happening by:
But today it appeared again. On one machine Add-Migration
wants to make these changes to the Identity tables while the other does not:
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)");
Upvotes: 0
Views: 496
Reputation: 1430
I never found out how or why the default value was different between two machines, but I did find out how to override it in code. You can set the MaxLengthForKeys
when registering Identity in Startup.cs
:
services.AddDefaultIdentity<ApplicationUser>(options => {
options.SignIn.RequireConfirmedAccount = true;
options.Stores.MaxLengthForKeys = 128;
})
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
There's also a related discussion about it here: https://github.com/dotnet/aspnetcore/issues/14503
Upvotes: 1