我正在尝试创建一个表,但我一直收到错误1005.):请帮忙!
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脚本执行完成:语句:8成功,1失败
答案 0 :(得分:0)
SQL 1005与外键问题有关。因此,请检查“RINK”,“OPPONENT”和“division / team”表是否存在指定的主键。
我认为对于Opponent表,你必须指定opponent_id作为外键来代替opponent_name。
请检查
答案 1 :(得分:-1)
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