MySQL Workbench Synchronization:CREATE TABLE中的错误,如果不是EXISTS`mydb` .timestamps`(

时间:2016-11-08 13:25:24

标签: mysql mysql-workbench

我是MySQL的新手。我尝试使用MySQL Workbench在新架构中创建几个表。我试图“将模型与数据库同步”,但它完成时出错。出于某种原因,MySQL Workbench自动生成的SQL包括CREATE TABLE IF NOT EXISTS mydbtimestamps .....这似乎是个问题。我能找到最接近的相关内容是在Workbench的架构GUI编辑器中,右边有一个名为Modeling Actions的窗格,它有一个名为timestamps的默认模板。我没有在我的简单测试项目中使用它。

我正在使用MySQL 5.7.16 Win64。 MySQL Workbench:6.3.7(build 1199CE)

我确实意识到它与将空值放入非空字段有关,但是,如果表/字段不是我的表的一部分,它是如何首先创建的?

任何人都可以带领我朝着正确的方向前进吗?我来自Access作为一个新手,这个系统是非常不同的。我无法让架构设计与MySQL同步。

*****************************************************************************
* MySQL Workbench auto-generated SQL - it is being made during Synchronize...
*****************************************************************************

    -- MySQL Workbench Synchronization
    -- Generated: 2016-11-08 06:30
    -- Model: New Model
    -- Version: 1.0
    -- Project: Name of the project
    -- Author: Turtle

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

    CREATE TABLE IF NOT EXISTS `mydb`.`timestamps` (
      `create_time`  NULL DEFAULT CURRENT_TIMESTAMP,
      `update_time`  NULL)
    ENGINE = InnoDB
    DEFAULT CHARACTER SET = utf8;

    CREATE TABLE IF NOT EXISTS `mydb`.`tblWorkLog` (
      `UserName` VARCHAR(50) NOT NULL,
      `tblUsers_UserName` VARCHAR(50) NOT NULL,
      PRIMARY KEY (`UserName`),
      INDEX `fk_tblWorkLog_tblUsers_idx` (`tblUsers_UserName` ASC),
      CONSTRAINT `fk_tblWorkLog_tblUsers`
        FOREIGN KEY (`tblUsers_UserName`)
        REFERENCES `mydb`.`tblUsers` (`UserName`)
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB
    DEFAULT CHARACTER SET = utf8;

    CREATE TABLE IF NOT EXISTS `mydb`.`tblUsers` (
      `UserName` VARCHAR(50) NOT NULL,
      `fName` VARCHAR(50) NULL DEFAULT NULL,
      `mName` VARCHAR(50) NULL DEFAULT NULL,
      `lName` VARCHAR(50) NULL DEFAULT NULL,
      `tblUserscol` VARCHAR(45) NULL DEFAULT NULL,
      `email` VARCHAR(255) NULL DEFAULT NULL,
      `tblWorkLog_UserName` INT(11) NOT NULL,
      PRIMARY KEY (`UserName`))
    ENGINE = InnoDB
    DEFAULT CHARACTER SET = utf8;

    CREATE TABLE IF NOT EXISTS `mydb`.`tblJobCodes` (
      `JobCode` VARCHAR(50) NOT NULL,
      `ShortName` VARCHAR(100) NULL DEFAULT NULL,
      `LongName` VARCHAR(255) NULL DEFAULT NULL,
      `Description` VARCHAR(4000) NULL DEFAULT NULL,
      PRIMARY KEY (`JobCode`))
    ENGINE = InnoDB
    DEFAULT CHARACTER SET = utf8;

    CREATE TABLE IF NOT EXISTS `mydb`.`tblRoles` (
      `RoleID` VARCHAR(25) NOT NULL,
      `Description` VARCHAR(255) NULL DEFAULT NULL,
      PRIMARY KEY (`RoleID`))
    ENGINE = InnoDB
    DEFAULT CHARACTER SET = utf8;


    SET SQL_MODE=@OLD_SQL_MODE;
    SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
    SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

-

*****************************************************************************
* Error message from 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 'NULL DEFAULT CURRENT_TIMESTAMP,
      `update_time`  NULL)
    ENGINE = InnoDB
    DEFAULT C' at line 2
    SQL Code:
            CREATE TABLE IF NOT EXISTS `mydb`.`timestamps` (
              `create_time`  NULL DEFAULT CURRENT_TIMESTAMP,
              `update_time`  NULL)
            ENGINE = InnoDB
            DEFAULT CHARACTER SET = utf8
    SQL script execution finished: statements: 3 succeeded, 1 failed
    Fetching back view definitions in final form.
    Nothing to fetch

1 个答案:

答案 0 :(得分:0)

每次尝试创建一个表。

但我相信问题是您使用NULLdefault

选中 examples

应该是:

 CREATE TABLE IF NOT EXISTS `mydb`.`timestamps` (
      `create_time`  DEFAULT CURRENT_TIMESTAMP,
      `update_time`)
    ENGINE = InnoDB
    DEFAULT CHARACTER SET = utf8;