Search code examples
.netentity-frameworkasp.net-coreasp.net-core-mvcentity-framework-core

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


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?


Solution

  • As per EF documentation you can use :

    Script-Migration 
    

    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.