MySQL 生成。sql 无法添加外键约束

MySQL generated .sql Cannot add foreign key constraint

这是 table 我得到 "Cannot add foreign key constraint" 错误。

-- -----------------------------------------------------
-- Table `mydb`.`Supervise1`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Supervise1` (
  `S1_Date` VARCHAR(45) NOT NULL,
  `S1_Contracter` VARCHAR(45) NOT NULL,
  `S1_Contractee` VARCHAR(45) NOT NULL,
  `S1_ID` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`S1_Contracter`, `S1_Contractee`, `S1_Date`, `S1_ID`),
  INDEX `Contracter_idx` (`S1_Contracter` ASC),
  INDEX `Contractee_idx` (`S1_Contractee` ASC),
  INDEX `S1_ID_idx` (`S1_ID` ASC),
  CONSTRAINT `S1_Date`
    FOREIGN KEY (`S1_Date`)
    REFERENCES `mydb`.`Contract` (`Date`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `S1_Contracter`
    FOREIGN KEY (`S1_Contracter`)
    REFERENCES `mydb`.`Contract` (`Contracter`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `S1_Contractee`
    FOREIGN KEY (`S1_Contractee`)
    REFERENCES `mydb`.`Contract` (`Contractee`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `S1_ID`
    FOREIGN KEY (`S1_ID`)
    REFERENCES `mydb`.`Lawfirm` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

合同和律师事务所table

-- -----------------------------------------------------
-- Table `mydb`.`Contract`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Contract` (
  `Date` VARCHAR(45) NOT NULL,
  `Contracter` VARCHAR(45) NOT NULL,
  `Contractee` VARCHAR(45) NOT NULL,
  INDEX `Contracter_idx` (`Contracter` ASC),
  INDEX `Contractee_idx` (`Contractee` ASC),
  PRIMARY KEY (`Contracter`, `Contractee`, `Date`),
  CONSTRAINT `Contracter`
    FOREIGN KEY (`Contracter`)
    REFERENCES `mydb`.`Agency` (`AgencyID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `Contractee`
    FOREIGN KEY (`Contractee`)
    REFERENCES `mydb`.`Agency` (`AgencyID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`Lawfirm`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Lawfirm` (
  `ID` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`ID`))
ENGINE = InnoDB;

我查看了一些类似问题的答案,但我的专栏是同一类型。我不明白为什么它会给我错误。如果需要,我可以提供更多信息。

已解决:检查 sql 是否存在同名约束。甚至它说外键错误是关于约束名称的。