Mysql Entity Framework issue - Specified key was too long; max key length is 3072 bytes

asp.net-core-2.0 asp.net-core-mvc entity-framework entity-framework-core mysql

Question

When I use this command:

$ dotnet ef database update

I get this error:

Specified key was too long; max key length is 3072 bytes

The table which cause this error is a built-in Microsoft table for user management:

CREATE TABLE `AspNetUserLogins` 
(
    `LoginProvider` varchar(767) NOT NULL,
    `ProviderKey` varchar(767) NOT NULL,
    `ProviderDisplayName` text NULL,
    `UserId` varchar(767) NOT NULL,

    PRIMARY KEY (`LoginProvider`, `ProviderKey`),
    CONSTRAINT `FK_AspNetUserLogins_AspNetUsers_UserId` 
        FOREIGN KEY (`UserId`) REFERENCES `AspNetUsers` (`Id`) 
        ON DELETE CASCADE
);

I tried to add this to OnModelCreating:

modelBuilder.Entity<Utilisateurs>(entity => entity.Property(m => m.NormalizedEmail).HasMaxLength(200));
modelBuilder.Entity<Utilisateurs>(entity => entity.Property(m => m.NormalizedUserName).HasMaxLength(200));
modelBuilder.Entity<IdentityRole>(entity => entity.Property(m => m.NormalizedName).HasMaxLength(200));
modelBuilder.Entity<IdentityUserLogin<string>>(entity => entity.Property(m => m.UserId).HasMaxLength(200));
modelBuilder.Entity<IdentityUserRole<string>>(entity => entity.Property(m => m.UserId).HasMaxLength(200));
modelBuilder.Entity<IdentityUserRole<string>>(entity => entity.Property(m => m.RoleId).HasMaxLength(200));
modelBuilder.Entity<IdentityUserToken<string>>(entity => entity.Property(m => m.UserId).HasMaxLength(200));
modelBuilder.Entity<IdentityUserClaim<string>>(entity => entity.Property(m => m.UserId).HasMaxLength(200));
modelBuilder.Entity<IdentityRoleClaim<string>>(entity => entity.Property(m => m.RoleId).HasMaxLength(200));

But it does not work anymore.

Thanks for your help

** EDIT **

I also tried:

modelBuilder.Entity<IdentityUserLogin<string>>(entity => entity.Property(m => m.LoginProvider).HasMaxLength(200));
modelBuilder.Entity<IdentityUserLogin<string>>(entity => entity.Property(m => m.ProviderKey).HasMaxLength(200));
1
6
1/22/2018 7:47:48 PM

Popular Answer

I used official MySql provider MySql.Data.EntityFrameworkCore which is in pre-release state and has some troubles with migrations. Then I changed to Pomelo.EntityFrameworkCore.MySql and updated database without any errors.

5
3/3/2018 9:59:49 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow