2013-04-04 145 views
0

我有两个完全相同的数据库表,一个prod和一个dev。每当我部署到开发数据库时,一切工作正常。并且prod数据库允许将此错误与我试图使用EF & MVC将数据写回数据库。EF外键属性不可为空

System.InvalidOperationException: The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted. 
    at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) 
    at System.Data.Entity.Internal.InternalContext.SaveChanges() 

当然,我已经检查这个http://blogs.msdn.com/b/dsimmons/archive/2010/01/31/deleting-foreign-key-relationships-in-ef4.aspx

好像没有问题,我的EF代码,纯粹db表问题 无论如何,我可以找到更多的细节?

+0

好文章能不能请你展示这两个表? – 2013-04-04 09:53:20

+0

您是否使用过Red-Gate SQL与同样的表进行比较,以防您丢失了什么?还有,你有参考表中的数据吗? – christiandev 2013-04-04 09:54:08

+0

我比较了两张表,它们是相同的。 – Kiddo 2013-04-04 14:17:20

回答