Entity Framework Core migrations through CI and CD in Azure DevOps

眉间皱痕 提交于 2021-01-28 08:39:53

问题


I have created an Entity Framework Core project and it is working fine and I am able to generate migrations through Visual Studio.

But I want to generate SQL scripts through Azure Devops CI and deployment through CD. I am unable to do it.

By adding this command

dotnet ef migrations script --project $(Build.SourcesDirectory)\SampleEFCoreApplication\SampleEFCoreApplication.csproj -o $(build.artifactstagingdirectory)\migrations\scripts.sql

This generates the entire SQL script. But next time, if I have to make any changes in my model, it again regenerates the entire SQL script. But I only want the changes to appear if I make any model changes. How can I do that ?

This is how my CI looks in Azure DevOps


回答1:


You can use the --idempotent option which will add code to the script so that only the appropriate migrations are applied to the database. This effectively makes the sql script the equivalent of running update-database in the package manager console.



来源:https://stackoverflow.com/questions/58027720/entity-framework-core-migrations-through-ci-and-cd-in-azure-devops

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!