实体框架5代码第一 - 如何“重新开始”? [英] Entity Framework 5 Code First - How to "start over"?
问题描述
有没有办法这样做?我想我将要删除__MigrationHistory表,或删除其内容。但是我不知道如何最好地继续这样做。
您应该可以执行以下操作: p>
-
手动更改数据库以反映模型中由迁移处理的更改。一切都应该正常工作,但数据库和迁移系统不同步。
-
运行
添加移植ManuallyUpdatedDatabase -IgnoreChanges
。这将创建一个完全为空的迁移,因此不会对数据库进行任何更改,但会确保系统知道所做的手动更改。
-
运行
更新数据库
应用空迁移。
从这里,一切都应照常运行。您的迁移中只有一个缺少的链接,因为您手动处理了一些更改。
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.
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.
这篇关于实体框架5代码第一 - 如何“重新开始”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!