我试图向competition
表添加约束,所以我做了:
ALTER TABLE `competition`
ADD CONSTRAINT `FK_competition_categories_competition_category_id`
FOREIGN KEY (`category`)
REFERENCES `swp`.`competition_categories` (`id`);
表competition_categories
具有以下设计:
CREATE TABLE IF NOT EXISTS `swp`.`competition_categories` (
`id` INT NOT NULL,
`description` VARCHAR(255) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
当我执行上面的查询时,我得到:
无法添加或更新子行:外键约束失败(
swp
。#sql-49a_c6
,CONSTRAINTFK_competition_categories_competition_category_id
FOREIGN KEY(category
)参考competition_categories
(id
))
答案 0 :(得分:1)
错误消息表示参考表中不存在外键值