问题描述
当我尝试使用前向工程师生成数据库时,出现这样的错误.
When I try to generate a database using Forward Engineer I get an error like this.
在服务器中执行SQL脚本
Executing SQL script in server
SQL代码:
-- -----------------------------------------------------
-- Table `mydb`.`Personal`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Personal` (
`idPersonal` INT NOT NULL,
`Experience` INT NULL,
`Department_idDepartment` INT NOT NULL,
`Date_of_accept` DATE NOT NULL,
`Date_of_release` DATE NULL,
`Human_idMan` INT NOT NULL,
PRIMARY KEY (`idPersonal`),
INDEX `fk_Personal_Department1_idx` (`Department_idDepartment` ASC) VISIBLE,
INDEX `fk_Personal_Human1_idx` (`Human_idMan` ASC) VISIBLE,
CONSTRAINT `fk_Personal_Department1`
FOREIGN KEY (`Department_idDepartment`)
REFERENCES `mydb`.`Department` (`idDepartment`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Personal_Human1`
FOREIGN KEY (`Human_idMan`)
REFERENCES `mydb`.`Human` (`idMan`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL脚本执行完成:语句:成功7次,失败1次
SQL script execution finished: statements: 7 succeeded, 1 failed
以最终形式获取后视图定义.什么都没拿
Fetching back view definitions in final form.Nothing to fetch
推荐答案
此处的问题是不同MySQL服务器版本之间的语法差异. MySQL Workbench 8.0 正在为MySQL服务器 8.0版自动生成CREATE UNIQUE INDEX
语句.
The problem here is the difference in syntax across different MySQL server versions. MySQL Workbench 8.0 is auto-generating CREATE UNIQUE INDEX
statement for the MySQL server version 8.0.
您的MySQL服务器版本很可能< 8.0..您可以从CREATE TABLE
语句中删除VISIBLE
关键字.它将如下所示:
Most likely, your MySQL server version < 8.0. You can remove VISIBLE
keyword from your CREATE TABLE
statement. It will look as follows:
CREATE TABLE IF NOT EXISTS `mydb`.`Personal` (
`idPersonal` INT NOT NULL,
`Experience` INT NULL,
`Department_idDepartment` INT NOT NULL,
`Date_of_accept` DATE NOT NULL,
`Date_of_release` DATE NULL,
`Human_idMan` INT NOT NULL,
PRIMARY KEY (`idPersonal`),
INDEX `fk_Personal_Department1_idx` (`Department_idDepartment` ASC),
INDEX `fk_Personal_Human1_idx` (`Human_idMan` ASC),
CONSTRAINT `fk_Personal_Department1`
FOREIGN KEY (`Department_idDepartment`)
REFERENCES `mydb`.`Department` (`idDepartment`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Personal_Human1`
FOREIGN KEY (`Human_idMan`)
REFERENCES `mydb`.`Human` (`idMan`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
从 MySQL Server 8.0文档, CREATE INDEX
的语法为:
From the MySQL Server 8.0 Docs, the syntax for CREATE INDEX
is:
CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name
[index_type]
ON tbl_name (key_part,...)
[index_option]
[algorithm_option | lock_option] ...
key_part: {col_name [(length)] | (expr)} [ASC | DESC]
index_option:
KEY_BLOCK_SIZE [=] value
| index_type
| WITH PARSER parser_name
| COMMENT 'string'
| {VISIBLE | INVISIBLE} -- Notice the option of VISIBLE / INVISIBLE
index_type:
USING {BTREE | HASH}
但是,{VISIBLE | INVISIBLE}
的此选项在 MySQL Server 5.7 中不可用.来自文档:
However, this option of {VISIBLE | INVISIBLE}
is not available in the MySQL Server 5.7. From Docs:
CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name
[index_type]
ON tbl_name (key_part,...)
[index_option]
[algorithm_option | lock_option] ...
key_part:
col_name [(length)] [ASC | DESC]
index_option:
KEY_BLOCK_SIZE [=] value
| index_type
| WITH PARSER parser_name
| COMMENT 'string'
index_type:
USING {BTREE | HASH}
这篇关于MySQL Workbench不会生成数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!