大家好!我是MySQL的新手。我使用Workbench工具创建了一个新模型(我的意思是,我自己没有编写任何代码串)。 当我试图改进它时,我得到了:
Executing SQL script in server
ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COMMENT '')
ENGINE = InnoDB' at line 8
SQL Code:
-- -----------------------------------------------------
-- Table `university`.`CITY`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `university`.`CITY` (
`ID_CITY` INT NOT NULL COMMENT '',
`CNAME` TEXT(15) NULL COMMENT '',
`POPULATION` INT NULL COMMENT '',
PRIMARY KEY (`ID_CITY`) COMMENT '')
ENGINE = InnoDB
SQL script execution finished: statements: 5 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
此外,当试图转发工程师默认的Workbench模型“sakila_full”时,我得到同样的事情:
Executing SQL script in server
ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COMMENT '',
INDEX `idx_actor_last_name` (`last_name` ASC) COMMENT '')
ENGINE ' at line 9
SQL Code:
-- -----------------------------------------------------
-- Table `sakila`.`actor`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `sakila`.`actor` (
`actor_id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '',
`first_name` VARCHAR(45) NOT NULL COMMENT '',
`last_name` VARCHAR(45) NOT NULL COMMENT '',
`last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
PRIMARY KEY (`actor_id`) COMMENT '',
INDEX `idx_actor_last_name` (`last_name` ASC) COMMENT '')
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
SQL script execution finished: statements: 5 succeeded, 1 failed
Fetching back view definitions in final form.
Could not get definition for sakila.customer_list from server
Could not get definition for sakila.film_list from server
Could not get definition for sakila.nicer_but_slower_film_list from server
Could not get definition for sakila.staff_list from server
Could not get definition for sakila.sales_by_store from server
Could not get definition for sakila.sales_by_film_category from server
Could not get definition for sakila.actor_info from server
7 views were read back.
提前致谢!
答案 0 :(得分:2)
嗯,BIG的问题在于,当使用" Forward Engineer"时,Mysql Workbench会添加自己产生错误的索引注释。或"同步模型"
当我使用6.0版时,此问题不存在。
答案 1 :(得分:1)
看起来你已经把COMMENT
字符串放得太远了。根据{{3}},只有列定义允许COMMENT
属性。这意味着您在INDEX
语句末尾附近列出的PRIMARY KEY
或CREATE
定义无效。
COMMENT ''
不是必需的,可以完全省略,特别是因为你将它们留空。否则,它们将用于列定义上的一些额外的人类可读元数据。
要使用此功能,请从索引和主键定义中删除COMMENT
属性。
CREATE TABLE IF NOT EXISTS `university`.`CITY` (
`ID_CITY` INT NOT NULL COMMENT '',
`CNAME` TEXT(15) NULL COMMENT '',
`POPULATION` INT NULL COMMENT '',
-- No COMMENT on PK
PRIMARY KEY (`ID_CITY`)
) ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `sakila`.`actor` (
`actor_id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '',
`first_name` VARCHAR(45) NOT NULL COMMENT '',
`last_name` VARCHAR(45) NOT NULL COMMENT '',
`last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
-- No COMMENT on PK or INDEX
PRIMARY KEY (`actor_id`),
INDEX `idx_actor_last_name` (`last_name` ASC)
) ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
或者没有任何空白COMMENT
的整个事情:
CREATE TABLE IF NOT EXISTS `university`.`CITY` (
`ID_CITY` INT NOT NULL COMMENT 'A comment that is not blank!',
`CNAME` TEXT(15) NULL,
`POPULATION` INT NULL,
PRIMARY KEY (`ID_CITY`)
) ENGINE = InnoDB;
(与另一张表相同)
MySQL通常非常擅长使用错误消息直接指向语法错误的来源:
查看与您的MySQL服务器版本对应的手册,以便在'COMMENT''附近使用正确的语法,
除了在语句末尾发生的错误(有些含糊不清)之外,在附近使用的正确语法将向您显示确切的错误。在上述情况下,COMMENT '')
会引导您选择COMMENT
后跟)
的{{1}}属性PRIMARY KEY
。从那里,查看手册(上面链接),了解您声明的每个部分的法律语法。