2025-05-27 14:39:23 +08:00
|
|
|
|
# 多数据库链接
|
|
|
|
|
|
|
|
|
|
|
|
> 创建数据库 命令:EntityFrameworkCore\Add-Migration InitialCreate(自定义命名,命名规范,知道每次做的什么操作)
|
|
|
|
|
|
> 更新数据库 命令:EntityFrameworkCore\Update-Database
|
|
|
|
|
|
|
|
|
|
|
|
# 多数据库连接时
|
|
|
|
|
|
|
|
|
|
|
|
> 创建数据库 命令:EntityFrameworkCore\Add-Migration -Context YMDeviceDbContext(自定义命名,命名规范,知道每次做的什么操作)
|
|
|
|
|
|
> 更新数据库 命令:EntityFrameworkCore\Update-Database -Context YMDeviceDbContext
|
|
|
|
|
|
|
|
|
|
|
|
# 迁移高级指令
|
|
|
|
|
|
|
|
|
|
|
|
> 创建迁移:migrationname为迁移名称
|
|
|
|
|
|
> dotnet ef migrations add InitialCreate 移除迁移(删除最近的一次迁移)
|
|
|
|
|
|
> dotnet ef migrations remove remove-migration 应用所有的迁移(使迁移文件应用到数据库)
|
|
|
|
|
|
> dotnet ef database update 指定版本进行迁移
|
|
|
|
|
|
> dotnet ef database update migrationName 生成对应版本的脚本
|
|
|
|
|
|
> dotnet ef migrations script Script-Migration 查看迁移列表
|
|
|
|
|
|
> dotnet ef migrations list 查看数据库上下文信息 dotnet ef dbcontext info
|
|
|
|
|
|
|
|
|
|
|
|
# 更新dotnet tools
|
|
|
|
|
|
> dotnet tool update --global dotnet-ef
|
2025-07-30 16:14:32 +08:00
|
|
|
|
|
2025-05-27 14:39:23 +08:00
|
|
|
|
> 生成SQL语句 Script-Migration -From 20220307064411_handlerMealPackage202203071443 -To 20220311084146_alterDevice202203111636 -Context ConsumerSystemDbContext
|
|
|
|
|
|
|
|
|
|
|
|
> Add-Migration alterAuditLogs202107011013 -c ConsumerSystemDbContext
|
|
|
|
|
|
|
|
|
|
|
|
> dotnet ef migrations add alterDevice202007190939 -c ConsumerSystemDbContext -s ../AIVE.ConsumerSystem.Apis
|
|
|
|
|
|
> dotnet ef database update -c ConsumerSystemDbContext
|
|
|
|
|
|
|
|
|
|
|
|
> dotnet ef migrations script 20210706022200_alterDevice202107061021 20210714013952_alterDevice202007140939 -o ./outupdate.sql -c ConsumerSystemDbContext -s ../AIVE.ConsumerSystem.Apis
|
|
|
|
|
|
|