gpt4 book ai didi

mysql - 创建数据库时: Error Code: 1215.无法添加外键约束

转载 作者:行者123 更新时间:2023-11-29 21:10:25 27 4
gpt4 key购买 nike

当我创建数据库时,在为此数据库创建“主”表时遇到了一些困难。

我认为外键和主键之间存在类型差异,但事实并非如此。

那么有人可以帮我吗?一定有什么地方我忽略了,但我找不到问题所在。

[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;

最佳答案

问题出在玩家表的主键上。它被配置为充当其他表的外键。

关于mysql - 创建数据库时: Error Code: 1215.无法添加外键约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36419284/

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