错误:System.Data.SqlClient.SqlException:INSERT 语句与 FOREIGN KEY 约束FK__Item__order__3AE27131"冲突.冲突发生在数据库pmall"、表dbo.ItemSaved"、列id"中.
Error: System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Item__order__3AE27131". The conflict occurred in database "pmall", table "dbo.ItemSaved", column '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 表中.
I don't really understand why if I a FK constraint on ItemSavedUnits.ItemID that is related to Item.ItemID and ItemUnits has no constraints at all why I'm getting a problem inserting into ItemSavedUnits. The ItemID I'm tryign to insert does exist in the Item table.
您确定 ItemId 92439 存在于 Item 表中,而不仅仅是 ItemUnits 中吗?
Are you absolutely sure that ItemId 92439 exists in the Item table, and not just in ItemUnits?
或
您的 select 语句是否返回 null?
Is your select statement returning null?
这篇关于INSERT 语句与 FOREIGN KEY 约束冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!