我在MySQL WB中建立了一个简单的模型。但是,当尝试建立数据库并运行时,会引发“正向工程”错误。
这是我得到的错误。
*FOREIGN KEY (`dep_iddep`)
REFEREN' at line 10
SQL代码:
-- -----------------------------------------------------
-- Table `mydb`.`eployee`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`eployee` (
`id` INT NOT NULL AUTO_INCREMENT,
`lnam` VARCHAR(45) NOT NULL,
`fname` VARCHAR(45) NOT NULL,
`dep_iddep` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_eployee_dep_idx` (`dep_iddep` ASC) VISIBLE,*
CONSTRAINT `fk_eployee_dep`
FOREIGN KEY (`dep_iddep`)
REFERENCES `mydb`.`dep` (`iddep`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 6 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
我试图从Google找到一些解决方案。我还在YouTube上看过一些视频,并尝试做到与视频中的视频完全一样,但是我总是会收到此错误。
WB生成的代码是:
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`dep`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`dep` (
`iddep` INT NOT NULL AUTO_INCREMENT,
`depname` VARCHAR(45) NOT NULL,
PRIMARY KEY (`iddep`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`eployee`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`eployee` (
`id` INT NOT NULL AUTO_INCREMENT,
`lnam` VARCHAR(45) NOT NULL,
`fname` VARCHAR(45) NOT NULL,
`dep_iddep` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_eployee_dep_idx` (`dep_iddep` ASC) VISIBLE,
CONSTRAINT `fk_eployee_dep`
FOREIGN KEY (`dep_iddep`)
REFERENCES `mydb`.`dep` (`iddep`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
它应该构成一个数据库。