无法向表

时间:2018-05-30 11:05:35

标签: mysql sql database

我试图向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,CONSTRAINT FK_competition_categories_competition_category_id FOREIGN KEY(category)参考competition_categoriesid))

1 个答案:

答案 0 :(得分:1)

错误消息表示参考表中不存在外键值