gpt4 book ai didi

mysql - #1452-无法添加或更新子行 :a foreign key constraint fails (`testdatabase` . `#sql-1

转载 作者:行者123 更新时间:2023-11-29 21:12:20 26 4
gpt4 key购买 nike

如何在现有表中添加外键

ALTER TABLE retailer_commission ADD FOREIGN KEY (Retailer_Id) REFERENCES retailer(Id)

enter image description here

最佳答案

由于 Retailer_id 的类型retailer_commission 中的列表和 Id retailer 中的列表的类型相同( int(11) ),您的错误必须有其他解释。

一个可能的解释是 retailer_commission表包含 Retailer_id 的记录引用 retailer 中的记录的值哪些不存在。

如果以下查询给出一个非空集,则返回的记录应被视为有问题:

SELECT rc.*
FROM retailer_commission rc LEFT JOIN retailer r
ON rc.Retailer_id = r.Id
WHERE r.Id IS NULL

关于mysql - #1452-无法添加或更新子行 :a foreign key constraint fails (`testdatabase` . `#sql-1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36256632/

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