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

.net asp.net-core asp.net-core-mvc entity-framework entity-framework-core

Question

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
58
9/22/2016 4:41:15 PM

Accepted Answer

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 <PreviousMigration> -To <LastMigration>

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

91
9/22/2016 5:32:52 PM

Popular Answer

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


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow