解決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

相關文章
相關標籤/搜索