How to generate code first migration script from a specific migration?

六月ゝ 毕业季﹏ 提交于 2020-01-05 03:36:12

问题


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



来源:https://stackoverflow.com/questions/39190738/how-to-generate-code-first-migration-script-from-a-specific-migration

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