错误报告:EF迁移DateTime键作为ForeignKey,迁移到Int键 - 中断迁移 [英] Bug Report: EF Migrations DateTime Key as ForeignKey, Migrate to Int Key - Breaks Migrations

查看:59
本文介绍了错误报告:EF迁移DateTime键作为ForeignKey,迁移到Int键 - 中断迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个类似的模型:

public class Class1 {
    public virtual ICollection<Class2> Class2s { get; set; }
public virtual Class2 CurrentClass2 { get; set; } } public class Class2 {     [Key]     public DateTime From { get; set; } }

运行update-database以进行操作然后更改模型:

Run update-database to get things going then change the Model:

public class Class1 { public virtual ICollection<Class2> Class2s { get; set; }
public virtual Class2 CurrentClass2 { get; set; }
}


公共类Class2 {
public int Id {get;组; }

public DateTime From {get;组; }
}

public class Class2 { public int Id { get; set; } public DateTime From { get; set; } }

所以Class2现在已经改变了它的PK,这将影响Class1指向它的FK。为fireworks运行update-database。

So Class2 now has changed its PK, which is going to affect Class1's FK pointing to it. Run update-database for fireworks.

你会得到一个例外,抱怨FK的类型与新PK的类型不匹配,并且将无法再迁移从这里开始。

You'll get an exception complaining that the type of the FK does not match the type of the new PK, and won't be able to migrate anymore from here.

我能够通过首先注释掉新ID字段和表之间的FK关系并更新所有相关数据库,然后取消注释ID字段并再次运行更新来解决此问题。在所有数据库上,最后取消注释关系
属性并最后一次运行更新。

I was able to workaround this by first commenting out the new ID field and the FK relationships between the tables and updating all related databases, then uncommenting the ID field and running update again on all DBs, and finally uncommenting the relationship properties and running update one last time.

推荐答案

感谢错误报告,我已经为它创建了一个问题:
http://entityframework.codeplex.com/workitem/776

团队将在那里调查并报告状态,而不是在论坛上。

The team will investigate and report status there, rather than here on the forums.


这篇关于错误报告:EF迁移DateTime键作为ForeignKey,迁移到Int键 - 中断迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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