我使用 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' (errno: 150)
我不明白!即使阅读代码本身,我也看不到任何错误!
有什么帮助吗?