在创建数据库时:错误代码:1215。无法添加外键约束

时间:2016-04-05 07:00:56

标签: mysql sql database database-design workbench

当我创建数据库时,我在创建" main"时遇到了一些困难。该数据库的表。

我认为外键和主键之间存在类型差异,但是没有。

那么有人可以帮助我吗?必须有一些我忽视的东西,但我无法找到问题所在。

[code]
-- -----------------------------------------------------
-- Table `boat`.`terms_and_conditions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `boat`.`terms_and_conditions` (
  `Terms_And_Conditions_Id` INT NOT NULL,
  `Terms_And_Conditions_Doc` VARCHAR(255) NULL DEFAULT NULL,
  `Terms_And_Conditions_Date` DATE NULL DEFAULT NULL,
  PRIMARY KEY (`Terms_And_Conditions_Id`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `boat`.`player`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `boat`.`player` (
  `Player_Id` INT NOT NULL,
  `Player_Firstname` VARCHAR(45) NULL DEFAULT NULL,
  `Player_Lastname` VARCHAR(45) NULL DEFAULT NULL,
  `Player_Password` VARCHAR(45) NULL,
  `Player_Budget` DOUBLE NULL,
  `Terms_Id` INT NOT NULL,
  PRIMARY KEY (`Player_Id`),
  INDEX `fk_player_terms_and_conditions1_idx` (`Terms_Id` ASC),
  CONSTRAINT `fk_player_player_result1`
    FOREIGN KEY (`Player_Id`)
    REFERENCES `boat`.`player_result` (`Player_Id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_player_supervisor_player1`
    FOREIGN KEY (`Player_Id`)
    REFERENCES `boat`.`supervisor_player` (`Player_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_player_terms_and_conditions1`
    FOREIGN KEY (`Terms_Id`)
    REFERENCES `boat`.`terms_and_conditions` (`Terms_And_Conditions_Id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

1 个答案:

答案 0 :(得分:0)

问题出现在播放器表的主键中。它被配置为像其他表的外键一样。