EF Core 迁移整理
PowerShell
Add-Migration InitialCreate
多数据源
Add-Migration InitialCreate -Context MyDbContext -OutputDir MigrationsSqlServerMigrations
Add-Migration InitialCreate -Context MySqliteDbContext -OutputDir MigrationsSqliteMigrations
Console
dotnet ef migrations add InitialCreate
dotnet ef migrations add InitialCreate --context MyDbContext --output-dir Migrations/SqlServerMigrations
dotnet ef migrations add InitialCreate --context MySqliteDbContext --output-dir Migrations/SqliteMigrations
更新数据库
PowerShell
Update-Database
Console
dotnet ef database update
删除迁移
PowerShell
Remove-Migration
Console
dotnet ef migrations remove
还原迁移
PowerShell
Update-Database LastGoodMigration
Console
dotnet ef database update LastGoodMigration
生成迁移Sql
PowerShell
Script-Migration
Script-Migration -From migrationName1 -To migrationName2 -Context ContextName
Console
dotnet ef migrations script
dotnet ef migrations script -From migrationName1 -To migrationName2 -Context ContextName
迁移脚本的帮助说明
我们可以通过命令来获取帮助说明
Get-Help about_EntityFrameworkCore
get-help Add-Migration -full
get-help Script-Migration -full