MYSQL ERROR 1005外键约束形成错误

时间:2017-11-18 21:23:27

标签: mysql database

我在尝试将我的sql文件上传到phpmyadmin

时收到此错误
#1005 - Can't create table `mydb`.`emts` (errno: 150 "Foreign key constraint is incorrectly formed") 

这是emts表:

CREATE TABLE IF NOT EXISTS `mydb`.`EMTS` (
  `idEMTS` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(45) NOT NULL,
  `nickname` VARCHAR(45) NOT NULL,
  `age` VARCHAR(45) NOT NULL,
  `number` VARCHAR(45) NOT NULL,
  `email` VARCHAR(45) NOT NULL,
  `city` VARCHAR(255) NOT NULL,
  `password` VARCHAR(45) NOT NULL,
  `shifts_idshifts` VARCHAR(45) NOT NULL,
  `bloodtype_id` INT NOT NULL,
  `street` VARCHAR(45) NOT NULL,
  `building` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`idEMTS`),
  INDEX `fk_EMTS_shifts1_idx` (`shifts_idshifts` ASC),
  INDEX `fk_EMTS_bloodtype1_idx` (`bloodtype_id` ASC),
  UNIQUE INDEX `nickname_UNIQUE` (`nickname` ASC),
  CONSTRAINT `fk_EMTS_shifts1`
    FOREIGN KEY (`shifts_idshifts`)
    REFERENCES `mydb`.`shifts` (`idshifts`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_EMTS_bloodtype1`
    FOREIGN KEY (`bloodtype_id`)
    REFERENCES `mydb`.`bloodtype` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

这是bloodtype表:

CREATE TABLE IF NOT EXISTS `mydb`.`bloodtype` (
  `type` INT NOT NULL,
  `id` INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;

这是shifts表:

CREATE TABLE IF NOT EXISTS `mydb`.`shifts` (
  `startdate` INT NOT NULL,
  `enddate` VARCHAR(45) NOT NULL,
  `day` VARCHAR(45) NOT NULL,
  `idshifts` INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`idshifts`))
ENGINE = InnoDB;

我不知道怎么回事?

0 个答案:

没有答案