gpt4 book ai didi

sql-server - INSERT 语句与 FOREIGN KEY 约束冲突

转载 作者:行者123 更新时间:2023-12-02 07:51:31 24 4
gpt4 key购买 nike

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 相关的 ItemSavedUnits.ItemID 进行 FK 约束,而 ItemUnits 根本没有约束,为什么我在插入 ItemSavedUnits 时遇到问题。我尝试插入的 ItemID 确实存在于 Item 表中。

最佳答案

您绝对确定 ItemId 92439 存在于 Item 表中,而不仅仅存在于 ItemUnits 中吗?

您的 select 语句返回 null 吗?

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com