在mysql

时间:2015-04-22 10:29:09

标签: mysql mysql-workbench collation

我有4个表,它们之间有一个关系。 Mother和Child-tables正在使用VARCHAR作为主键和子表中的外键。但我无法弄清楚为什么零售商 - 公羊给我错误?

   CREATE TABLE IF NOT EXISTS `mydb`.`retailer` (
  `retailer_number` VARCHAR(255) NOT NULL,
  `retailer_name` VARCHAR(45) NULL,
  PRIMARY KEY (`retailer_number`))
ENGINE = InnoDB;


CREATE TABLE IF NOT EXISTS `mydb`.`rma` (
  `rma_id` INT(11) NOT NULL AUTO_INCREMENT,
  `retailer_retailer_number` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`rma_id`),
  CONSTRAINT `fk_rma_retailer1`
    FOREIGN KEY (`retailer_retailer_number`)
    REFERENCES `mydb`.`retailer` (`retailer_number`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci;
CREATE INDEX `fk_rma_retailer1_idx` ON `mydb`.`rma` (`retailer_retailer_number` ASC);

-- -----------------------------------------------------
-- This is working
-- -----------------------------------------------------


CREATE TABLE IF NOT EXISTS `mydb`.`mother` (
  `motherName` VARCHAR(255) NOT NULL,
  `test` VARCHAR(45) NULL,
  PRIMARY KEY (`motherName`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`child`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`child` (
  `idchild` INT NOT NULL AUTO_INCREMENT,
  `childName` VARCHAR(45) NULL,
  `mother_motherName` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`idchild`),
  CONSTRAINT `fk_child_mother`
    FOREIGN KEY (`mother_motherName`)
    REFERENCES `mydb`.`mother` (`motherName`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE INDEX `fk_child_mother_idx` ON `mydb`.`child` (`mother_motherName` ASC);

错误

150422 13:10:28表mydb / rma的外键约束出错:

FOREIGN KEY (`retailer_retailer_number`)
REFERENCES `mydb`.`retailer` (`retailer_number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)

ENGINE = InnoDB DEFAULT CHARACTER SET = utf8 COLLATE = utf8_unicode_ci: 在引用的表中找不到索引 引用的列显示为第一列或列类型 在表中,引用的表与约束不匹配。 请注意,ENUM和SET的内部存储类型已更改 使用> = InnoDB-4.1.12创建的表,以及旧表中的此类列 新表中的此类列不能引用它们。 见http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html 正确的外键定义。

问题

如果原因是整理,我怎样才能立即在MySQLWorkbench中更改它?或者来自哪里?

0 个答案:

没有答案