实体框架5代码第一 - 如何“重新开始”? [英] Entity Framework 5 Code First - How to "start over"?

查看:64
本文介绍了实体框架5代码第一 - 如何“重新开始”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的应用程序中成功地使用了EF 5 Code First。我有大约40张桌子。但是,我遇到了一个问题,我似乎可以让Migrations正确处理。所以,我想做的是以某种方式告诉EF将数据库的当前模式视为一个新的起点,并从此开始管理它。这样,我可以手动进行必要的模式更改,然后告诉EF基本上从这一点开始。



有没有办法这样做?我想我将要删除__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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆