mysql workbench转发工程师错误1064

时间:2016-01-05 20:30:10

标签: mysql mysql-workbench

逗人,

我已经创建了一个数据库模型,并希望使用Workbench顺利地将其编写到MySQL。

下面是WB生成的代码:

    -- MySQL Workbench Forward Engineering

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';

-- -----------------------------------------------------
-- Schema resume_db
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema resume_db
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `resume_db` DEFAULT CHARACTER SET latin1 ;
USE `resume_db` ;

-- -----------------------------------------------------
-- Table `resume_db`.`vacancies`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `resume_db`.`vacancies` (
  `id` INT(11) NOT NULL,
  `title` VARCHAR(256) NOT NULL,
  `htmlDesc` TEXT NOT NULL,
  `issueDate` DATETIME NOT NULL,
  `expiryDate` DATETIME NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `resume_db`.`job_history`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `resume_db`.`job_history` (
  `id` INT GENERATED ALWAYS AS () VIRTUAL,
  `employerName` MEDIUMTEXT NOT NULL,
  `employement_duration` VARCHAR(100) NULL,
  `job_title` VARCHAR(256) NOT NULL,
  `duties` VARCHAR(200) NULL,
  `applications_id` INT NOT NULL,
  PRIMARY KEY (`id`, `applications_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `resume_db`.`education_record`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `resume_db`.`education_record` (
  `id` INT GENERATED ALWAYS AS () VIRTUAL,
  `school_name` VARCHAR(256) NOT NULL,
  `degree_period` VARCHAR(256) NOT NULL,
  `degree_title` VARCHAR(256) NOT NULL,
  `degree_notes` VARCHAR(256) NULL,
  `applications_id` INT NOT NULL,
  PRIMARY KEY (`id`, `applications_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `resume_db`.`social_networks`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `resume_db`.`social_networks` (
  `id` INT GENERATED ALWAYS AS () VIRTUAL,
  `social_network` VARCHAR(256) NOT NULL,
  `profile_url` VARCHAR(256) NOT NULL,
  `applications_id` INT NOT NULL,
  PRIMARY KEY (`id`, `applications_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `resume_db`.`applications`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `resume_db`.`applications` (
  `id` INT GENERATED ALWAYS AS () VIRTUAL,
  `name` VARCHAR(500) NULL,
  `photo_url` VARCHAR(256) NULL,
  `title` VARCHAR(10) NOT NULL,
  `videoUrl` VARCHAR(256) NULL,
  `email` VARCHAR(256) NOT NULL,
  `vacancyID` INT NULL,
  `location` VARCHAR(256) NULL,
  `skills` MEDIUMTEXT NULL,
  `htmlCoverLetter` LONGTEXT NOT NULL,
  `resume_url` VARCHAR(256) NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_applications_vacancies_idx` (`vacancyID` ASC),
  CONSTRAINT `fk_applications_vacancies`
    FOREIGN KEY (`vacancyID`)
    REFERENCES `resume_db`.`vacancies` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_applications_job_history1`
    FOREIGN KEY (`id`)
    REFERENCES `resume_db`.`job_history` (`applications_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_applications_education_record1`
    FOREIGN KEY (`id`)
    REFERENCES `resume_db`.`education_record` (`applications_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_applications_social_networks1`
    FOREIGN KEY (`id`)
    REFERENCES `resume_db`.`social_networks` (`applications_id`)
    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;

遗憾的是,一旦执行,我收到以下错误信息:

    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 'GENERATED ALWAYS AS () VIRTUAL,
  `employerName` MEDIUMTEXT NOT NULL,
  `employe' at line 5
SQL Code:
        -- -----------------------------------------------------
        -- Table `resume_db`.`job_history`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `resume_db`.`job_history` (
          `id` INT GENERATED ALWAYS AS () VIRTUAL,
          `employerName` MEDIUMTEXT NOT NULL,
          `employement_duration` VARCHAR(100) NULL,
          `job_title` VARCHAR(256) NOT NULL,
          `duties` VARCHAR(200) NULL,
          `applications_id` INT NOT NULL,
          PRIMARY KEY (`id`, `applications_id`))
        ENGINE = InnoDB

SQL script execution finished: statements: 6 succeeded, 1 failed

Fetching back view definitions in final form.
Nothing to fetch

任何线索?

2 个答案:

答案 0 :(得分:0)

来自MY SQL手册......我认为你需要一个表达式。

生成的列定义具有以下语法:

col_name data_type [GENERATED ALWAYS] AS (expression)
  [VIRTUAL | STORED] [UNIQUE [KEY]] [COMMENT comment]
  [[NOT] NULL] [[PRIMARY] KEY]

AS(表达式)表示生成列并定义用于计算列值的表达式。 AS可以在GENERATED ALWAYS之前,以使列的生成性质更明确。表达式中允许或禁止的构造将在后面讨论。

http://dev.mysql.com/doc/refman/5.7/en/create-table.html

答案 1 :(得分:0)

您的意思是AUTO_INCREMENT

  CREATE TABLE IF NOT EXISTS `resume_db`.`job_history` (
         `id` INT AUTO_INCREMENT,
          `employerName` MEDIUMTEXT NOT NULL,
          `employement_duration` VARCHAR(100) NULL,
          `job_title` VARCHAR(256) NOT NULL,
          `duties` VARCHAR(200) NULL,
          `applications_id` INT NOT NULL,
          PRIMARY KEY (`id`, `applications_id`))
        ENGINE = InnoDB

否则,为什么要生成虚拟ID列?