如何将迁移添加到MYSQL数据库?

时间:2019-06-06 12:45:16

标签: mysql .net-core hosting ef-migrations

我只是将.Net核心站点托管到smarterasp.net,但是当我尝试在MYSql上更新数据库时出现错误

Failed executing DbCommand (397ms) [Parameters=[], CommandType='Text', CommandTimeout='30']

CREATE TABLE `AspNetUserRoles` (
    `UserId` varchar(255) NOT NULL,
    `RoleId` varchar(255) NOT NULL,
    CONSTRAINT `PK_AspNetUserRoles` 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
);

指定的密钥太长;最大密钥长度为1000个字节

and my site is showing this in homepage

1 个答案:

答案 0 :(得分:1)

MySql对最大索引键长度有限制。当您加入UserId和RoleId时,它会导致一个长索引键(以字节为单位,而不是字符),因此您应将配置文件中innodb_large_prefix的配置更改为ON。如mysql doc所说,这将设置索引键前缀最多3072个字节。

[mysqld]
innodb_large_prefix = 1

您还需要更改:

   SET GLOBAL innodb_file_format=Barracuda;
   SET GLOBAL innodb_file_per_table=1;
   SET GLOBAL innodb_large_prefix=1;
   logout & login (to get the global values);
   ALTER TABLE tbl ROW_FORMAT=DYNAMIC;  -- (or COMPRESSED)

当您使用255 * 2个字符作为密钥时,可能会导致超过1000个字节(取决于您的字符默认设置)。

您可以看看mysql docummentation 您可以更多here