I have used MySQL Workbench to model my table and somehow there's a logic error in the SQL to create the tables generated by the software.
Here are the codes:
-- -----------------------------------------------------
-- 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;
As result I'm getting the following message:
#1005 - Can't create table 'trickani_main.quiz_level' (errno: 150)
I don't get it! I can't see any error even by reading the code itself!
Any help?
You might want to try making your PKs not unsigned.
See this question/answer: Adding table with FOREIGN KEY to a MySQL database causes errno 150
Edit: you might want to try either making all your PKs signed or all your PKs unsigned. My guess is that the definition for quiz_level
, which isn't currently shown in your question, has a PK whose signedness differs from the other tables.