EF(实体框架)4.3迁移工具在EF 4.1 DB上不起作用 [英] EF (Entity Framework) 4.3 Migration tool does not work on EF 4.1 DB

本文介绍了EF(实体框架)4.3迁移工具在EF 4.1 DB上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改一个使用EF 4.1(Code First)开发的数据库。我将项目升级为EF 4.3,并按照以下步骤操作:
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx


由于目标数据库是使用早于EF 4.3的Code First版本创建的
,并且
不包含迁移历史记录表,因此无法构建下一个迁移。要开始对此数据库使用迁移
,请确保当前模型与
目标数据库兼容,并执行迁移更新过程。 (在Visual
Studio中,您可以使用Package Manager中的Update-Database命令
控制台执行迁移更新过程)。


我想知道如何迁移EF 4.1(Code First)DB?此外,DB是活的,有数据,我不能删除表。

解决方案

您需要创建一个空迁移并执行它对您的模型进行更改。它将为您创建迁移历史记录表。之后,您可以使用迁移进行新更改。我写了关于这个的演练文章主题。


I want to modify one DB which was developed with EF 4.1 (Code First). I upgraded the project into EF 4.3 and follow this steps: http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx

Everything is going well, but when I want to test on current DB (EF 4.1 Code First), Update-Database raise this error:

Cannot scaffold the next migration because the target database was created with a version of Code First earlier than EF 4.3 and does not contain the migrations history table. To start using migrations against this database, ensure the current model is compatible with the target database and execute the migrations Update process. (In Visual Studio you can use the Update-Database command from Package Manager Console to execute the migrations Update process).

I was wondering how I can migrate an EF 4.1 (Code First) DB? Moreover that DB is live and has data and I cannot drop tables.

解决方案

You need to create an empty migration and execute it prior to doing changes to your model. It will create the migration history table for you. After that you can use migrations for new changes. I wrote walkthrough article about this topic.

这篇关于EF(实体框架)4.3迁移工具在EF 4.1 DB上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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