How to generate code first migration script from a

2019-07-24 16:22发布

问题:

I have a production and a development database. Now I want to generate a sql script based on a specific migration. When I enter the line to generate the script I get this error:

'201608121243147_AutomaticMigration' is not a valid migration. Explicit migrations must be used for both source and target when scripting the upgrade between them.

The command I use is as follows:

Update-Database -Script -SourceMigration:201608121243147_AutomaticMigration -TargetMigration:201608281101542_AutomaticMigration

When I execute the command get-migrations I can see those two migrations are in the list. The target migration is also my latest migration, but when I omit this parameter I get the same exception.

What am i doing wrong? What do I have to do to fix this?

回答1:

Try removing the semicolon after SourceMigration and after TargetMigration:

Update-Database -Script -SourceMigration 201608121243147_AutomaticMigration -TargetMigration 201608281101542_AutomaticMigration


回答2:

This works for me.

Update-DataBase -Script -SourceMigration:"Version1" -TargetMIgration:"Version2"

Regards Abdul