Add-Migration
Add-Migration init -Context AppliactionContext -OutPut-Dir Data
Add-Migration init -Context IntegrationEventLogContext -OutputDir IntegrationEventMigrations
update-database -Context IntegrationEventLogContext
update-database -Context AppliactionContext
两个数据上下文
builder.Services.AddDbContext<AppliactionContext>(options => { //使用内存数据库 //options.UseInMemoryDatabase("test"); string mysqlStr = builder.Configuration.GetConnectionString("mysql") ?? throw new UserDomainException("mysql连接字符串为null"); options.UseMySql(mysqlStr, new MySqlServerVersion(new Version(8, 0, 27))); }); //添加事件总线日志数据库配置 builder.Services.AddDbContext<IntegrationEventLogContext>(options => { // 内存数据库 // options.UseInMemoryDatabase("test"); //mysql 数据库 string mysqlStr = builder.Configuration.GetConnectionString("mysql") ?? throw new UserDomainException("mysql连接字符串为null"); options.UseMySql(mysqlStr, new MySqlServerVersion(new Version(8, 0, 27)), dbOptions => { //数据迁移 dbOptions.MigrationsAssembly(Assembly.GetExecutingAssembly().GetName().Name); //开启失败重试 dbOptions.EnableRetryOnFailure(maxRetryCount: 15, TimeSpan.FromSeconds(15), null); }); });
生成迁移文件的位置
"ConnectionStrings": { "redis": "192.168.0.168:6379", "mysql": "server=192.168.0.168;port=3306;database=UserDDD;pwd=123456;uid=root;" },