Update Entity-Framework-Core-Other-DBMS.md

remove "Change the Migrations DbContext" plate, because no need to manually set database provider after v2.9+
add "Change the Migrations DbContext Factory" plate, because the switch to MySQL, we also need to modify the DbContextOptionsBuilder
mark "DBMS restrictions" plate, Add history modification record
pull/6345/head
Min.Ling 4 years ago committed by GitHub
parent 97fbcf3c46
commit b71e1294af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -62,22 +62,25 @@ MySQL连接字符串与SQL Server连接字符串不同. 所以检查你的解决
通常需要更改 `.DbMigrator``.Web` 项目里面的 `appsettings.json` ,但它取决于你的解决方案结构.
## 更改迁移DbContext
## 更改迁移DbContext Factory
MySQL DBMS与SQL Server有一些细微的差异. 某些模块数据库映射配置(尤其是字段长度)会导致MySQL出现问题. 例如某些[IdentityServer模块](Modules/IdentityServer.md)表就存在这样的问题,它提供了一个选项可以根据你的DBMS配置字段.
启动模板包含***YourProjectName*MigrationsDbContextFactory**这是EF Core控制台命令所必须的类比如[Add-Migration](https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/#generating--running-migrations)和[Update-Database](https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/#generating--running-migrations)在切换到MySql数据库时我们同时也需要修改`DbContextOptionsBuilder`
启动模板包含*YourProjectName*MigrationsDbContext,它负责维护和迁移数据库架构. 此DbContext基本上调用依赖模块的扩展方法来配置其数据库表.
在 *YourProjectName*MigrationsDbContextFactory 类中找到以下代码:
打开 *YourProjectName*MigrationsDbContext 更改 `builder.ConfigureIdentityServer();` 行,如下所示:
````csharp
var builder = new DbContextOptionsBuilder<TestMigrationsDbContext>()
.UseSqlServer(configuration.GetConnectionString("Default"));
````
将其替换为:
````csharp
builder.ConfigureIdentityServer(options =>
{
options.DatabaseProvider = EfCoreDatabaseProvider.MySql;
});
var builder = new DbContextOptionsBuilder<TestMigrationsDbContext>()
.UseMySql(configuration.GetConnectionString("Default"));
````
然后 `ConfigureIdentityServer()` 方法会将字段长度设置为超过MySQL的限制. 如果在创建或执行数据库迁移时遇到任何问题请参考相关模块文档.
如果在创建或执行数据库迁移时遇到任何问题请参考相关模块文档
## 重新生成迁移
@ -105,5 +108,6 @@ builder.ConfigureIdentityServer(options =>
options.DatabaseProvider = EfCoreDatabaseProvider.MySql;
});
```
v2.9+版本无需手动设置 ([版本历史](https://github.com/abpframework/abp/blob/dev/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerModelBuilderConfigurationOptions.cs))
相关讨论: https://github.com/abpframework/abp/issues/1920
相关讨论: https://github.com/abpframework/abp/issues/1920

Loading…
Cancel
Save