首页 > 数据库技术 > 详细

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

时间:2018-03-22 18:38:13      阅读:1838      评论:0      收藏:0      [点我收藏+]

  和Identity的问题相似,通过替换掉默认的PersistedGrantDbContext来实现

  新建一个 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中注入我们自己实现的方法

services
.AddIdentityServer()
//这里省略了其他的方法
.AddOperationalStore<PersistedGrantMysqlDbContext>(options =>//PersistedGrantMysqlDbContext替代默认方法 {//存储Token Grants等信息 options.ConfigureDbContext = builder => { //builder.UseSqlServer(Configuration.GetConnectionString("DefaultConnection") builder.UseMySQL(Configuration.GetConnectionString("MysqlConnection") , sql => sql.MigrationsAssembly(migrationAssembly)); }; })

 之后执行数据库迁移命令 数据库可以正常生成了!






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

原文:https://www.cnblogs.com/CandLx/p/8625413.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!