abp vnext 中有许多ids4的表,生成时出了一些问题。
将Docs模块从sql server 换成mysql后,运行IGeekFan.DbMigrator项目,迁移表结构 用EF CORE生成数据库时报如下问题
MySql.Data.MySqlClient.MySqlException:“BLOB/TEXT column 'Value' used in key specification without a key length”
此异常最初是在此调用堆栈中引发的:
MySqlConnector.Core.ServerSession.ReceiveReplyAsyncAwaited(System.Threading.Tasks.ValueTask<System.ArraySegment<byte>>) (位于 [ServerSession.cs] 中)(navigate-to-context:0)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
MySqlConnector.Core.ResultSet.ReadResultSetHeaderAsync(MySqlConnector.Protocol.Serialization.IOBehavior) (位于 [ResultSet.cs] 中)(navigate-to-context:3)
mysql 连接串
"ConnectionStrings": {
"Default": "Data Source=localhost;Port=3306;User ID=root;Password=123456;Initial Catalog=IGeekFan;Charset=utf8mb4;SslMode=none;Max pool size=5;"
},
sql连接串
//"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=IGeekFan;Trusted_Connection=True;MultipleActiveResultSets=true"
在程序包管理控制台上执行Update-Database能出现具体是哪个表引起的。
Failed executing DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE `IdentityServerApiSecrets` (
`Type` varchar(250) CHARACTER SET utf8mb4 NOT NULL,
`Value` longtext CHARACTER SET utf8mb4 NOT NULL,
`ApiResourceId` char(36) NOT NULL,
`Description` varchar(2000) CHARACTER SET utf8mb4 NULL,
`Expiration` datetime(6) NULL,
CONSTRAINT `PK_IdentityServerApiSecrets` PRIMARY KEY (`ApiResourceId`, `Type`, `Value`),
CONSTRAINT `FK_IdentityServerApiSecrets_IdentityServerApiResources_ApiResou~` FOREIGN KEY (`ApiResourceId`) REFERENCES `IdentityServerApiResources` (`Id`) ON DELETE CASCADE
);
我们把这个sql放到navicat premium中执行,然后就发现,Value字段类型为longtext,却将其作为 primary key,如果我们改为如下内容,就OJBK了
CREATE TABLE `IdentityServerApiSecrets` (
`Type` varchar(250) CHARACTER SET utf8mb4 NOT NULL,
`Value` longtext CHARACTER SET utf8mb4 NOT NULL,
`ApiResourceId` char(36) NOT NULL,
`Description` varchar(2000) CHARACTER SET utf8mb4 NULL,
`Expiration` datetime(6) NULL,
CONSTRAINT `PK_IdentityServerApiSecrets` PRIMARY KEY (`ApiResourceId`, `Type`),
CONSTRAINT `FK_IdentityServerApiSecrets_IdentityServerApiResources_ApiResou~` FOREIGN KEY (`ApiResourceId`) REFERENCES `IdentityServerApiResources` (`Id`) ON DELETE CASCADE
);
修改无法创建表IdentityServerApiSecurity的错误
这一步直接修改【xxxxBangleAbpMigrationsDbContext.cs】文件,builder.ConfigureIdentityServer方法,就可以解决,不需要修改长度
builder.ConfigureIdentityServer(options =>
{
options.DatabaseProvider = EfCoreDatabaseProvider.MySql;
});
- 有人遇到同样问题,解决方案dotnet9
网友评论