我已經使用MySQL Workbench來建模我的表,並且在SQL中有一個邏輯錯誤來創建軟件生成的表。MySQL不能接受我的表
這裏是代碼:
-- -----------------------------------------------------
-- 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 )
我不明白!即使通過閱讀代碼本身,我也看不到任何錯誤!
任何幫助?
我覺得你不向我們展示了'quiz_level'創建代碼... –
通常,當工作臺抱怨它的外鍵的問題,我覺得。如果您禁用FK並運行它會通過嗎? – scoota269
這是*全部*的代碼?因爲你提供給我們的SQL中沒有引用表'quiz_level'。 – Sammitch