gpt4 book ai didi

php - 我无法在 MySQL 中创建表

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

ALTER TABLE items 
ADD CONSTRAINT member_1
FOREIGN KEY(Member_ID)
REFERENCES users(UserID)
ON UPDATE CASCADE
ON DELETE CASCADE;

MySQL 说:

1452 - Cannot add or update a child row: a foreign key constraint fails (`shop`.`#sql-1650_234`, CONSTRAINT `member_1` FOREIGN KEY (`Member_ID`) REFERENCES `users` (`UserID`) ON DELETE CASCADE ON UPDATE CASCADE)

最佳答案

在创建新约束之前,您必须修复不正确的值:

Update items SET member_ID = null
where member_ID not in (select userID from users)

关于php - 我无法在 MySQL 中创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37764007/

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