-- Constraints for table `variation`
--
ALTER TABLE `variation`
ADD FOREIGN KEY (`parent`) REFERENCES `variation` (`id`),
ADD FOREIGN KEY (`scale`) REFERENCES `scale` (`id`),
ADD FOREIGN KEY (`user`) REFERENCES `users` (`user_id`);
--
错误
ERROR 1452(23000)第277行:无法添加或更新子行:a 外键约束失败(
getsy
。#sql-f44_2a
,CONSTRAINT#sql-f44_2a_ibfk_2
外键(scale
)参考scale
(id
))
此表变体
CREATE TABLE IF NOT EXISTS `variation` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`parent` bigint(20) DEFAULT NULL,
`scale` bigint(20) DEFAULT NULL,
`value` varchar(255) NOT NULL,
`user` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `parent` (`parent`,`scale`,`value`,`user`),
KEY `scale` (`scale`),
KEY `user` (`user`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=101 ;
帮帮我......
感谢
答案 0 :(得分:0)
variation
表格列scale
中的内容似乎包含表scale
列id
中缺少的值。
您可以使用以下查询检查缺失值:
SELECT DISTINCT a.scale FROM
variation AS a LEFT JOIN scale AS b ON a.scale = b.id
WHERE b.id IS NULL;