Entity Framework 5 Code First - How to “start over”?

青春壹個敷衍的年華 提交于 2019-12-20 10:48:29

问题


I've been using EF 5 Code First, successfully, in my app. I have roughly 40 tables. However, I've run into an issue that I can seem to get Migrations to handle correctly. So, what I would like to do is to somehow tell EF to treat the current schema of the database as a new starting point, and start managing it from this point. This way, I can make the necessary schema change manually, and then tell EF to essentially start over from this point.

Is there a way I can do this? I presume I'm going to have to delete the __MigrationHistory table, or remove its contents. But I'm not sure how best to proceed with doing this.


回答1:


You should be able to do the following:

  • Change your database manually to reflect the changes in the model that wont be handled by a migration. Everything should work now, but the database and the migration system are out of sync.

  • Run Add-Migration ManuallyUpdatedDatabase -IgnoreChanges. This creates a migration that is completely empty, so it wont make any changes to the database, but it will make sure that the system knows about the manual changes that have been made. That way the manual changes wont be included in the next migration you create.

  • Run Update-Database to apply the empty migration.

From here on everything should work as usual. You just have a "missing link" in your migrations because you have handled some changes manually.



来源:https://stackoverflow.com/questions/16219905/entity-framework-5-code-first-how-to-start-over

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