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));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With