我已经使用MySQL Workbench对我的表进行建模,并且在某种程度上SQL中存在逻辑错误以创建由软件生成的表。
以下是代码:
-- -----------------------------------------------------
-- Table `trickani_main`.`user`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `trickani_main`.`user` (
`iduser` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`fb_id` VARCHAR(50) NOT NULL ,
`email` VARCHAR(40) NOT NULL ,
`first_name` VARCHAR(15) NOT NULL ,
`gender` VARCHAR(1) NOT NULL ,
PRIMARY KEY (`iduser`) ,
UNIQUE INDEX `fb_id_UNIQUE` (`fb_id` ASC) ,
UNIQUE INDEX `email_UNIQUE` (`email` ASC) )
ENGINE = InnoDB
AUTO_INCREMENT = 1;
-- -----------------------------------------------------
-- Table `trickani_main`.`quiz_list`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `trickani_main`.`quiz_list` (
`id_quiz_list` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`difficult` TINYINT(4) NOT NULL ,
PRIMARY KEY (`id_quiz_list`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `trickani_main`.`user_quiz_list`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `trickani_main`.`user_quiz_list` (
`iduser` INT UNSIGNED NOT NULL ,
`id_quiz_list` INT UNSIGNED NOT NULL ,
`level_reached` INT UNSIGNED NOT NULL DEFAULT 0 ,
PRIMARY KEY (`iduser`, `id_quiz_list`) ,
INDEX `fk_quiz_list_user1_idx` (`iduser` ASC) ,
INDEX `fk_user_quiz_list_quiz_list1_idx` (`id_quiz_list` ASC) ,
CONSTRAINT `fk_quiz_list_user1`
FOREIGN KEY (`iduser` )
REFERENCES `trickani_main`.`user` (`iduser` )
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_user_quiz_list_quiz_list1`
FOREIGN KEY (`id_quiz_list` )
REFERENCES `trickani_main`.`quiz_list` (`id_quiz_list` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 1;
结果我收到以下消息:
#1005 - 无法创建表'trickani_main.quiz_level'(错误号:150)
我不明白!即使阅读代码本身,我也看不到任何错误!
任何帮助?
答案 0 :(得分:0)
答案 1 :(得分:-1)
你可能想尝试让你的PK没有签名。
请参阅此问题/答案:Adding table with FOREIGN KEY to a MySQL database causes errno 150
编辑:您可能想要尝试使所有PK签名或所有PK未签名。我的猜测是quiz_level
的定义(当前未在您的问题中显示)有一个PK,其签名与其他表格不同。