In ASP.NET Core Web MVC Application, I have not been able to successfully create the tables needed for Identity in MySQL
Steps to reproduce (in Visual Studio) :
(o => o.UseMySQL(Configuration. GetConnectionString("DefaultConnection")));
"DefaultConnection": "Server=localhost;Database=TestDB; Uid=root;Pwd=YOURPASSWORDHERE"
dotnet ef migrations add CreateIdentitySchema -o Data\Migrations
Then, of course, update the database with:
dotnet ef database update
However, we get the following error:
CREATE TABLE `AspNetUserRoles` ( `UserId` varchar(767) NOT NULL, `RoleId` varchar(767) NOT NULL, PRIMARY KEY (`UserId`, `RoleId`), CONSTRAINT `FK_AspNetUserRoles_AspNetRoles_RoleId` FOREIGN KEY (`RoleId`) REFERENCES `AspNetRoles` (`Id`) ON DELETE CASCADE, CONSTRAINT `FK_AspNetUserRoles_AspNetUsers_UserId` FOREIGN KEY (`UserId`) REFERENCES `AspNetUsers` (`Id`) ON DELETE CASCADE ); MySql.Data.MySqlClient.MySqlException (0x80004005): Specified key was too long; max key length is 3072 bytes
This is because our Snapshot is generating our UserId to have a varchar length of 767 and our RoleId to have a varchar length of 767. In MySQL, each char (in UTF8) is worth 3 bytes. Hence 1534*3 > 3072 bytes. However, Identity only requires these columns to have a length of 128 bytes.
So my question is this: how do we get the migration to reflect this needed change?
User contributions licensed under CC BY-SA 3.0