1

当我尝试创建新表时,出现错误:

错误代码:1005。无法创建表“db”。“db_timesheet_check”(错误号:150)

我认为的问题是创建外键。没有外键它可以工作,但是当我尝试添加键时出现错误。

我究竟做错了什么?

DROP TABLE IF EXISTS `db`.`db_check_causes`;

CREATE  TABLE IF NOT EXISTS `db`.`db_check_causes` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
  `code` VARCHAR(8) NOT NULL ,
  `info` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX `id_UNIQUE` (`id` ASC) ,
  UNIQUE INDEX `code_UNIQUE` (`code` ASC) );

DROP TABLE IF EXISTS `db`.`db_timesheet_check`;

CREATE  TABLE IF NOT EXISTS `db`.`db_timesheet_check` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
  `TSId` INT(10) UNSIGNED NOT NULL ,
  `causeId` INT(10) UNSIGNED NOT NULL ,
  `checked` BIT NOT NULL DEFAULT 0 ,
  `checkedBy` INT(10) UNSIGNED NULL ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX `id_UNIQUE` (`id` ASC) ,
  INDEX `TSId` (`TSId` ASC) ,
  INDEX `causeId` (`causeId` ASC) ,
  INDEX `checkedBy` (`checkedBy` ASC) ,
  CONSTRAINT `TSId`
    FOREIGN KEY (`TSId` )
    REFERENCES `db`.`db_timesheet` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `causeId`
    FOREIGN KEY (`causeId` )
    REFERENCES `db`.`db_check_causes` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `checkedBy`
    FOREIGN KEY (`checkedBy` )
    REFERENCES `db`.`db_user` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);
4

0 回答 0