I am trying to create a table but I keep getting Error 1005. ): Please help!
Executing SQL script in server
ERROR: Error 1005: Can't create table 'czhen_hockey_db.hockey_db' (errno: 150)
SQL Code:
-- -----------------------------------------------------
-- Table `czhen_hockey_db`.`hockey_db`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `czhen_hockey_db`.`hockey_db` (
`id` INT NOT NULL,
`Date` VARCHAR(45) NOT NULL,
`Time` VARCHAR(45) NOT NULL,
`rink_id` INT NOT NULL,
`division/team_id` INT NOT NULL,
`opponent_id` INT NOT NULL,
INDEX `fk_hockey_db_rink_idx` (`rink_id` ASC),
INDEX `fk_hockey_db_division/team1_idx` (`division/team_id` ASC),
INDEX `fk_hockey_db_opponent1_idx` (`opponent_id` ASC),
PRIMARY KEY (`id`),
CONSTRAINT `fk_hockey_db_rink`
FOREIGN KEY (`rink_id`)
REFERENCES `czhen_hockey_db`.`rink` (`rink_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_hockey_db_division/team1`
FOREIGN KEY (`division/team_id`)
REFERENCES `czhen_hockey_db`.`division/team` (`division/team_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_hockey_db_opponent1`
FOREIGN KEY (`opponent_id`)
REFERENCES `czhen_hockey_db`.`opponent` (`opponent_name`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 8 succeeded, 1 failed
SQL 1005 is related to Foreign key problem. So please check whether "RINK", "OPPONENT" and "division/team" tables exist with specified primary keys.
I think for Opponent table you have to specify opponent_id as foreign key in place of opponent_name.
Please check
CREATE TABLE IF NOT EXISTS `czhen_hockey_db`.`hockey_db` (
`id` INT NOT NULL,
`Date` VARCHAR(45) NOT NULL,
`Time` VARCHAR(45) NOT NULL,
`rink_id` INT NOT NULL,
`division/team_id` INT NOT NULL,
`opponent_id` INT NOT NULL,
INDEX `fk_hockey_db_rink_idx` (`rink_id` ASC),
INDEX `fk_hockey_db_division/team1_idx` (`division/team_id` ASC),
INDEX `fk_hockey_db_opponent1_idx` (`opponent_id` ASC),
PRIMARY KEY (`id`),
CONSTRAINT `fk_hockey_db_rink`
FOREIGN KEY (`rink_id`)
REFERENCES `czhen_hockey_db`.`rink` (`rink_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_hockey_db_division/team1`
FOREIGN KEY (`division/team_id`)
REFERENCES `czhen_hockey_db`.`division/team` (`division/team_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_hockey_db_opponent1`
FOREIGN KEY (`opponent_id`)
REFERENCES `czhen_hockey_db`.`opponent` (`opponent_name`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.