The INSERT statement conflicted with the FOREIGN KEY constraint(INSERT 语句与 FOREIGN KEY 约束冲突)
问题描述
错误: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'.
这是我的桌子:
- id
- ItemID(在此表中设置为 Item.id 的 FK)
- ...等
这是我的插入语句:
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 约束冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:INSERT 语句与 FOREIGN KEY 约束冲突


基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01