错误:System.Data.SqlClient.SqlException:INSERT语句与FOREIGN KEY约束“ FK__Item__order__3AE27131”发生冲突。数据库“ pmall”的表“ dbo.ItemSaved”的列“ id”中发生了冲突。

这是我的桌子:
ItemSavedUnits

ID
ItemID(在此表中,将FK设置为​​Item.id)
...等等。

这是我的插入语句:

insert into ItemSavedUnits (ItemID, name, Price)
select ItemID, name,Price
from ItemUnits where ItemID = 92439

我真的不明白为什么我对与Item.ItemID和ItemUnits相关的ItemSavedUnits.ItemID进行FK约束时根本没有约束,为什么我在插入ItemSavedUnits时遇到问题。我尝试插入的ItemID确实存在于Item表中。

最佳答案

您是否完全确定ItemId是否存在于Item表中,而不仅仅是ItemUnits中?

要么

您的select语句是否返回null?

关于sql-server - INSERT语句与FOREIGN KEY约束冲突,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1828376/

10-09 00:37
查看更多