我试图在MySQL Workbench中设计EER图并继续设计这个错误。我对此非常陌生,所以任何帮助都会受到赞赏,以及我可以用来改进的任何东西。附上的是错误消息和SQL脚本。 谢谢!
ERROR: Error 1005: Can't create table 'mnn09c.ASSIGN' (errno: 150)
CREATE TABLE IF NOT EXISTS `mnn09c`.`ASSIGN` (
`ASN_ID` INT NOT NULL,
`ASN_START_D` DATETIME NOT NULL,
`ASN_END_D` DATETIME NOT NULL,
`EMP_ID` INT NOT NULL,
PRIMARY KEY (`ASN_ID`),
CONSTRAINT `fk_ASSIGN_PRODUCT1`
FOREIGN KEY (`ASN_ID`)
REFERENCES `mnn09c`.`PRODUCT` (`ASN_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 13 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Executing SQL script in server
ERROR: Error 1005: Can't create table 'mnn09c.ASSIGN' (errno: 150)
CREATE TABLE IF NOT EXISTS `mnn09c`.`ASSIGN` (
`ASN_ID` INT NOT NULL,
`ASN_START_D` DATETIME NOT NULL,
`ASN_END_D` DATETIME NOT NULL,
`EMP_ID` INT NOT NULL,
PRIMARY KEY (`ASN_ID`),
CONSTRAINT `fk_ASSIGN_PRODUCT1`
FOREIGN KEY (`ASN_ID`)
REFERENCES `mnn09c`.`PRODUCT` (`ASN_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 13 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
___________________________________________________________
`SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
DROP SCHEMA IF EXISTS `mnn09c` ;
CREATE SCHEMA IF NOT EXISTS `mnn09c` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
;
SHOW WARNINGS;
USE `mnn09c` ;
-- -----------------------------------------------------
-- Table `mnn09c`.`PRODUCT`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mnn09c`.`PRODUCT` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `mnn09c`.`PRODUCT` (
`PROD_ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`PROD_DURATION` INT NOT NULL,
`PROD_EVAL` VARCHAR(45) NOT NULL,
`ASN_ID` INT NOT NULL,
PRIMARY KEY (`PROD_ID`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `mnn09c`.`ASSIGN`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mnn09c`.`ASSIGN` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `mnn09c`.`ASSIGN` (
`ASN_ID` INT NOT NULL,
`ASN_START_D` DATETIME NOT NULL,
`ASN_END_D` DATETIME NOT NULL,
`EMP_ID` INT NOT NULL,
PRIMARY KEY (`ASN_ID`),
CONSTRAINT `fk_ASSIGN_PRODUCT1`
FOREIGN KEY (`ASN_ID`)
REFERENCES `mnn09c`.`PRODUCT` (`ASN_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `mnn09c`.`EMPLOYEE`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mnn09c`.`EMPLOYEE` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `mnn09c`.`EMPLOYEE` (
`EMP_ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`EMP_LNAME` VARCHAR(45) NOT NULL,
`EMP_FNAME` VARCHAR(45) NOT NULL,
`EMP_ADDR` VARCHAR(45) NOT NULL,
`DEPT_ID` INT NOT NULL,
`DIVS_ID` INT NOT NULL,
PRIMARY KEY (`EMP_ID`),
INDEX `fk_EMPLOYEE_DEPT_idx` (`DEPT_ID` ASC),
CONSTRAINT `fk_EMPLOYEE_DEPT`
FOREIGN KEY (`DEPT_ID`)
REFERENCES `mnn09c`.`DEPT` (`DEPT_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_EMPLOYEE_ASSIGN1`
FOREIGN KEY (`EMP_ID`)
REFERENCES `mnn09c`.`ASSIGN` (`EMP_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `mnn09c`.`DIVISION`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mnn09c`.`DIVISION` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `mnn09c`.`DIVISION` (
`DIVS_ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`DIVS_NAME` VARCHAR(45) NOT NULL,
`DIVS_URL` VARCHAR(45) NOT NULL,
`DIVS_EMAIL` VARCHAR(45) NOT NULL,
`DIVS_LOC` VARCHAR(45) NOT NULL,
`EMP_ID` INT NOT NULL,
PRIMARY KEY (`DIVS_ID`),
UNIQUE INDEX `DIVS_ID_UNIQUE` (`DIVS_ID` ASC),
UNIQUE INDEX `DIVS_URL_UNIQUE` (`DIVS_URL` ASC),
UNIQUE INDEX `DIVS_EMAIL_UNIQUE` (`DIVS_EMAIL` ASC),
INDEX `fk_DIVISION_EMPLOYEE1_idx` (`EMP_ID` ASC),
CONSTRAINT `fk_DIVISION_EMPLOYEE1`
FOREIGN KEY (`EMP_ID`)
REFERENCES `mnn09c`.`EMPLOYEE` (`EMP_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `mnn09c`.`DEPT`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mnn09c`.`DEPT` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `mnn09c`.`DEPT` (
`DEPT_ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`DEPT_NAME` VARCHAR(45) NOT NULL,
`DEPT_LOCATION` VARCHAR(45) NOT NULL,
`DEPT_EMAIL` VARCHAR(45) NOT NULL,
`DEPT_URL` VARCHAR(45) NOT NULL,
`EMP_ID` INT NOT NULL,
`DIVS_ID` INT NOT NULL,
PRIMARY KEY (`DEPT_ID`),
UNIQUE INDEX `DEPT_ID_UNIQUE` (`DEPT_ID` ASC),
UNIQUE INDEX `DEPT_EMAIL_UNIQUE` (`DEPT_EMAIL` ASC),
UNIQUE INDEX `DEPT__UNIQUE` (`DEPT_URL` ASC),
INDEX `fk_DEPT_DIVISION1_idx` (`DIVS_ID` ASC),
INDEX `fk_DEPT_EMPLOYEE1_idx` (`EMP_ID` ASC),
CONSTRAINT `fk_DEPT_DIVISION1`
FOREIGN KEY (`DIVS_ID`)
REFERENCES `mnn09c`.`DIVISION` (`DIVS_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_DEPT_EMPLOYEE1`
FOREIGN KEY (`EMP_ID`)
REFERENCES `mnn09c`.`EMPLOYEE` (`EMP_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `mnn09c`.`MANAGE`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mnn09c`.`MANAGE` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `mnn09c`.`MANAGE` (
`MANAGER_ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`MANAGER_ID`),
UNIQUE INDEX `MANAGER_ID_UNIQUE` (`MANAGER_ID` ASC))
ENGINE = InnoDB;
SHOW WARNINGS;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
答案 0 :(得分:0)
这是外键错误,这意味着您尝试插入的表或数据违反了某些外键约束。
请参阅:http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html
通常这是由第三方程序使用SQL转储创建程序引起的,该程序不知道如何正确转储外键,或者是旧版本的mysqldump。
从头开始下载MySQL 5.5或5.6客户端和mysqldump数据库。
您也可以通过重新排序SQL文件以在ASSIGN表之前创建PRODUCT表来使其工作。
答案 1 :(得分:0)
发生此问题是因为多一个外键具有相同的名称! 在工作台中,在选择具有FK的表后,转到外键,并更改外键的名称(不是列名,只有FK名)。 例如:FK colum name:idUser。 FK名称:idUser。将此表上的FK名称更改为idUserA。在任何其他也使用idUser作为FK的表中,将FK的名称更改为idUserB。 OK?
我希望你能理解我。 =)