EF外键属性不可为空

时间:2013-04-04 09:50:45

标签: asp.net-mvc entity-framework

我有两个完全相同的数据库表,一个prod和一个dev。 每当我部署到dev数据库时,一切正常。并且prod数据库允许抛出这个错误,我试图使用EF& MVC将数据写回数据库。

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表问题 无论如何,我可以找到更多细节?

1 个答案:

答案 0 :(得分:0)