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

Gabriel Castillo Prada picture Gabriel Castillo Prada · Sep 22, 2016 · Viewed 68.5k times · Source

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 EF Core?

Answer

Gasper picture Gasper · Sep 22, 2016

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.