FirstDivision
FirstDivision

Reputation: 1430

EF Core Code First with Identity differences between migrations on different machines

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:

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

Answers (1)

FirstDivision
FirstDivision

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

Related Questions