使用单独的迁移汇编

问题描述 投票:0回答:1

关注Microsoft关于使用单独的迁移项目的说明,我构建了一个解决方案模型,看起来类似于以下内容:

\
 +-- Application.csproj
 +-- ProjectContainingDbContext.csproj
 +-- MigrationProject.SqlServer.csproj
 +-- MigrationProject.Postgres.csproj
我使用以下语法来生成迁移组件的内容:

dotnet ef migrations add Initial --project MigrationProject.SqlServer.csproj


这步骤正常。 我实际上不是在使用迁移组件,而是需要生成SQL,因为我使用

DbUp

在生产中应用迁移。  但是,看来脚本生成尊重
--project
标志,即,以下看起来与
DbContext
相同,因此未能生成迁移SQL:

dotnet ef migrations script --output path_for_sql_files --project MigrationProject.SqlServer.csproj


有人可以建议解决这个问题吗? 我使用EF Core9.0.2.

相关,命令

dotnet ef migrations -has-pending-model-changes

也未能尊重

--project

参数(在github上作为特征请求提出为EF core
sissue35637。)
因此,事实证明这一切都很好,

If
entity-framework-core database-migration
1个回答
0
投票
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

    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.