关注Microsoft关于使用单独的迁移项目的说明,我构建了一个解决方案模型,看起来类似于以下内容:
\
+-- Application.csproj
+-- ProjectContainingDbContext.csproj
+-- MigrationProject.SqlServer.csproj
+-- MigrationProject.Postgres.csproj
我使用以下语法来生成迁移组件的内容:
dotnet ef migrations add Initial --project MigrationProject.SqlServer.csproj
DbUp
在生产中应用迁移。 但是,看来脚本生成尊重
--project
标志,即,以下看起来与
DbContext
相同,因此未能生成迁移SQL:
dotnet ef migrations script --output path_for_sql_files --project MigrationProject.SqlServer.csproj
相关,命令
dotnet ef migrations -has-pending-model-changes
--project
参数(在github上作为特征请求提出为EF coresissue35637。)
。因此,事实证明这一切都很好,If
dotnet ef migrations script
命令或dotnet ef has-pending-model-changes
命令之前构建迁移组件。
回想起来很明显,但对我而言并不明显,文档没有说明需要构建组件的任何内容 - 请记住,当您运行
dotnet ef migrations add
命令时,它会在之前和之后进行包含dbcontext的构建。 ...,您在构建管道中需要的是:
dotnet build MigrationProject.SqlServer.csproj
dotnet ef migrations script --output path_for_sql_files --project MigrationProject.SqlServer.csproj