简体   繁体   English

工作台中的MySQL表创建错误

[英]MySQL table creation error in workbench

I'm new to MySQL and I'm running version 5.7.19-log (At least thats what I'm getting from command line client) with Workbench 6.3.9 Community edition. 我是MySQL的新手,正在运行带有Workbench 6.3.9 Community Edition的5.7.19-log版本(至少从命令行客户端获得的版本)。 My problem is I'm trying to create a simple table with auto-generated id using the UI, however when I execute the generated script it throws me the following error: 我的问题是我正在尝试使用UI创建一个具有自动生成的ID的简单表,但是当我执行生成的脚本时,会引发以下错误:

  Operation failed: There was an error while applying the SQL script to the database.
Executing:
CREATE TABLE `travelportaldb`.`user` (
  `user_id` INT GENERATED ALWAYS AS () VIRTUAL,
  `name` VARCHAR(45) NOT NULL,
  `account_id` VARCHAR(15) NULL,
  `account_currency` CHAR(3) NULL,
  `account_balance` DECIMAL NULL,
  PRIMARY KEY (`user_id`));

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 ') VIRTUAL,
  `name` VARCHAR(45) NOT NULL,
  `account_id` VARCHAR(15) NULL,
  `ac' at line 2
SQL Statement:
CREATE TABLE `travelportaldb`.`user` (
  `user_id` INT GENERATED ALWAYS AS () VIRTUAL,
  `name` VARCHAR(45) NOT NULL,
  `account_id` VARCHAR(15) NULL,
  `account_currency` CHAR(3) NULL,
  `account_balance` DECIMAL NULL,
  PRIMARY KEY (`user_id`))

This is the script that it generated: 这是它生成的脚本:

CREATE TABLE `travelportaldb`.`user` (
  `user_id` INT GENERATED ALWAYS AS () VIRTUAL,
  `name` VARCHAR(45) NOT NULL,
  `account_id` VARCHAR(15) NULL,
  `account_currency` CHAR(3) NULL,
  `account_balance` DECIMAL NULL,
  PRIMARY KEY (`user_id`));

I have no idea what's wrong. 我不知道怎么了 I'm from the oracle background and the query seems to be fine except the auto generated apart which I have no idea about. 我来自oracle背景,除了自动生成的查询(我不知道)之外,查询似乎还不错。

Please help. 请帮忙。

Thanks. 谢谢。

When you switch on the generated flag in MySQL Workbench the column details fields will change a bit to allow setting the required options for a generated column: 当您开启的generated在MySQL Workbench中旗列细节字段将发生变化了一下,允许设置生成列所需的选项:

在此处输入图片说明

Most important here is the Expression field. 这里最重要的是Expression字段。 For a generated column you have to specify an expression which is used for generation. 对于生成的列,您必须指定用于生成的表达式。 Obviously you didn't do that and hence in your generated SQL the column definitions are wrong (empty parentheses, where an expression should be). 显然您没有这样做,因此在您生成的SQL中,列定义是错误的(空括号,应在其中的表达式)。

PS: You can also see the used server version in the Session tab page: PS:您还可以在“ Session选项卡页面中查看使用的服务器版本:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM