[英]Cannot upgrade a system from EF 4.3.1 to 5
Background: I have upgraded my system from Entity Framework 4.3.1 to 5, and moved from VS 2010 to VS 2012. I have also upgraded to MVC4 from MVC3. 背景:我已将系统从Entity Framework 4.3.1升级到5,并从VS 2010升级到VS2012。我也已从MVC3升级到MVC4。 I use EF Migrations Code First.
我首先使用EF迁移代码。
All this is working perfectly on my machine, and therefore I try to upgrade my test server with the new code. 所有这些在我的机器上都可以正常运行,因此我尝试使用新代码升级测试服务器。
First I installed .Net 4.5 on the server, without incident (including all subsequent windows updates). 首先,我在服务器上安装了.Net 4.5,没有发生任何故障(包括所有后续的Windows更新)。 Then I verified that the system continues to run on the upgraded server, which it does.
然后,我验证了系统是否继续在升级后的服务器上运行。
Then I build a deployment package with the new "Publish..." wizard in VS2012. 然后,我在VS2012中使用新的“发布...”向导构建了一个部署程序包。 Here I decide not to check the checkbox called "Execute Code First Migrations (runs on application start)", because I want to do this with my own explicit call to migrate.exe, directly after install.
在这里,我决定不选中称为“执行代码优先迁移(在应用程序启动时运行)”的复选框,因为我想在安装后直接用自己的显式调用来迁移。
Now, I try to upgrade the test system. 现在,我尝试升级测试系统。 The deployment works without problems, but when I try to run the call to migrate.exe I first get the message:
部署工作没有问题,但是当我尝试运行对migration.exe的调用时,我首先收到消息:
"No pending code-based migrations." “没有待处理的基于代码的迁移。” then there comes a big red text block, stating that:
然后出现一个红色的大文本块,指出:
"ERROR: Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration." “错误:由于存在挂起的更改并且禁用了自动迁移,因此无法更新数据库以匹配当前模型。要么将挂起的模型更改写入基于代码的迁移,要么启用自动迁移。将DbMigrationsConfiguration.AutomaticMigrationsEnabled设置为true即可启用自动迁移。”
And when I try to use the system, this call to verify the validity of the database returns false: context.Database.CompatibleWithModel(true) This is not accepted by my system, and it shuts down. 当我尝试使用系统时,此调用以验证数据库的有效性返回false:context.Database.CompatibleWithModel(true)我的系统不接受此操作,它会关闭。
Then I revert to my previous package, after replacing the CreatedOn column in __MigratHistory, and the system works like a charm again. 然后,在替换__MigratHistory中的CreatedOn列之后,我恢复到以前的程序包,并且系统再次像超级按钮一样工作。 Below is the sql sript i use to revert...
以下是我用来还原的SQL Sript ...
alter table dbo.__MigrationHistory
add CreatedOn datetime null
go
Update s
Set s.CreatedOn = CAST(SUBSTRING(s.MigrationId, 1, 8) as datetime) + CAST(SUBSTRING(s.MigrationId, 9, 2) + ':' + SUBSTRING(s.MigrationId, 11, 2) as time),
s.ProductVersion = '4.3.1'
from dbo.__MigrationHistory s
Any sugestions on what I am doing wrong? 是否对我做错了什么表示怀疑?
do changes in Configuration.cs file ==> 在Configuration.cs文件中进行更改==>
public Configuration()
{
AutomaticMigrationsEnabled = **true**;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.