简体   繁体   English

无法将系统从EF 4.3.1升级到5

[英]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.

相关问题 EF4.3.1中的MaxLength属性 - MaxLength Attribute in EF4.3.1 将updatemodel与EF4.3.1一起使用时出现InvalidOperationException - InvalidOperationException when using updatemodel with EF4.3.1 如何使用EF 4.3.1映射列名称? - How to map column names with EF 4.3.1? Membership.GetUser在我的Razor文件中从EF5升级到EF6后抛出MissingMethodException - Membership.GetUser throwing MissingMethodException after upgrade from EF5 to EF6 in my Razor file EF Core - 仅在一张表中升级到 .net 6 后无法获得鉴别器值 - EF Core - cannot get discriminator value after upgrade to .net 6 in only one table 无法从和EF对象获取智能感知属性 - Cannot get intellisense properties from and EF object EF代码优先4.3.1迁移:即使没有任何变化,也始终播种数据 - EF Code First 4.3.1 Migrations: Always seeding data even though nothing changed 无法使用 EF Core 从 MS SQL 服务器检索数据 - Cannot retrieve data from MS SQL Server using EF Core 升级到 EF 6.1.1 使 [NotMapped] 的效果消失 - Upgrade to EF 6.1.1 makes effect of [NotMapped] disappear 无法从 'System.Threading.Tasks.Task 转换<string> '到'字符串'</string> - cannot convert from 'System.Threading.Tasks.Task<string>' to 'string'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM