gpt4 book ai didi

MySQL无法创建带外键的表

转载 作者:行者123 更新时间:2023-12-01 00:13:22 24 4
gpt4 key购买 nike

CREATE  TABLE `assessmentbookdb`.`MCQs` (
`id` INT NOT NULL AUTO_INCREMENT ,
`MCQAnswer` VARCHAR(200) NOT NULL ,
`QuestionID` INT NOT NULL ,
PRIMARY KEY (`id`) ,
INDEX `QuestionID` (`QuestionID` ASC) ,
CONSTRAINT `QuestionID`
FOREIGN KEY (`QuestionID` )
REFERENCES `assessmentbookdb`.`Question` (`QuestionID` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;

消息日志:

错误 1005:无法创建表“assessmentbookdb.mcqs”(错误号:121)SQL语句:

CREATE  TABLE `assessmentbookdb`.`MCQs` (
`id` INT NOT NULL AUTO_INCREMENT ,
`MCQAnswer` VARCHAR(200) NOT NULL ,
`QuestionID` INT NOT NULL ,
PRIMARY KEY (`id`) ,
INDEX `QuestionID` (`QuestionID` ASC) ,
CONSTRAINT `QuestionID`
FOREIGN KEY (`QuestionID` )
REFERENCES `assessmentbookdb`.`Question` (`QuestionID` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB

最佳答案

仔细检查:

  • key 的名称是唯一的
  • 您耦合的两个键具有完全相同的数据类型(此处:INT NOT NULL),甚至是签名
  • 引用字段实际存在

关于MySQL无法创建带外键的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11775653/

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