解决NETCORE2.0 IdentityServer4.EntityFramework 在Mysql上字段过长的问题

  和Identity的问题类似,经过替换掉默认的PersistedGrantDbContext来实现sql

  新建一个 PersistedGrantMysqlDbContext类 实现默认提供的PersistedGrantDbContext
public class PersistedGrantMysqlDbContext : PersistedGrantDbContext<PersistedGrantDbContext> { public PersistedGrantMysqlDbContext(DbContextOptions<PersistedGrantMysqlDbContext> options, OperationalStoreOptions storeOptions) : base(options, storeOptions) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.PersistedGrant", e => e.Property<string>("Data").HasMaxLength(20000));//这里原来是5W 超长了
 } }

 

  在Startup中注入咱们本身实现的方法数据库

 1 services.AddIdentityServer()  2 //这里省略了其余的方法
 3 .AddOperationalStore<PersistedGrantMysqlDbContext>(options =>//PersistedGrantMysqlDbContext替代默认方法
 4 {//存储Token Grants等信息
 5     options.ConfigureDbContext = builder =>
 6  {  7         //builder.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")
 8         builder.UseMySQL(Configuration.GetConnectionString("MysqlConnection")  9         , sql => sql.MigrationsAssembly(migrationAssembly)); 10  }; 11 })

 

 以后执行数据库迁移命令 数据库能够正常生成了!ide

相关文章
相关标签/搜索