Code First Migration Entity Framework 6 Empty Up/Down

戏子无情 提交于 2019-12-11 10:40:08

问题


The problem I'm having is that when I "Add-Migration", it seems that no comparison against the target database is done and the Up/Down methods are empty.

This starts from me targeting different environments. The migration changes work fine when I update-database and it targets one particular database, my dev database.

When I change the connection string to target another database, another dev box on another server, and try to add-migration for that particular environment, the Up/Down methods are always empty.

I tried targeting an update-database to roll back changes to a previous migration at the 2nd dev box but it didn't change anything.

Is there anything that I need to specifically do if I'm migrating code-first changes from one environment to another?


回答1:


You don't need to add a new migration, you need to force EF to run all the old ones. Try specifying the source and target migrations:

Update-Database -SourceMigration: $InitialDatabase -TargetMigration: AddPostAbstract  

Another option would be to generate a script that you can run against the other database by adding -Script to the command.

See https://msdn.microsoft.com/en-us/data/jj591621.aspx#script

If you have a lot of migrations you could role them up by deleting them and doing a fresh add-migration.




回答2:


What I ended up doing was generating an initial migration and then compared the schema between the two servers (@Steve Greene commented with a great link describing what I did to do the comparison here: http://www.techbubbles.com/sql-server/schema-compare-for-sql-server-in-visual-studio-2013/). I then, painstakingly, walked through the migration code and commented out what was unnecessary.

Once the migration ran successfully, everything went back to running smoothly.

I'm not sure if there is a better way of handling it, but this worked for me.




回答3:


I've been struggling with this empty up() and down() showing up at every attempt for hours. Tried even starting over a new project .. didn't work ..

Until I've had the idea of setting up, in visual studio, the data project as the default startup project of the solution .. then magic happened!

Can't really say if it's a solution (because I still don't see the connection to the base problem) but may be it could help somebody which visual studio's cosmic sign is the same as mine :)



来源:https://stackoverflow.com/questions/29851114/code-first-migration-entity-framework-6-empty-up-down

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