2013-04-04 110 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

回答