Can I generate script of a migration with EF code first and .net core

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

I'm building a MVC application with .Net Core and I need to generate the script of a migration.

With EF6 I did run the command

update-database -script

but when I try to do the same with .net Core is throwing the next exception:

Update-Database : A parameter cannot be found that matches parameter name 'script'

Do you know if there is an equivalent for EF7?

回答1:

As per EF documentation you can use Script-Migration command.

If you want to just script all the migrations you can simply call it from Package Manager console like that. If you want to just script the changes from the last migration you can call it like this:

Script-Migration -From  -To 

Be sure to check the docs, there're a few more options to the command.



回答2:

You can use dotnet core cli to generate script

dotnet ef migrations script 

Also you can put this to file with new power shell out-file command.

dotnet ef migrations script | out-file ./script.sql


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