mysql工作台输出错误1064中的数据库转发工程

uidvcgyl  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(353)

这是mysql workbench在正向工程时创建的脚本:

-- 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='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- -----------------------------------------------------
-- Schema DialogueFlowDB
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema DialogueFlowDB
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `DialogueFlowDB` DEFAULT CHARACTER SET utf8 ;
USE `DialogueFlowDB` ;

-- -----------------------------------------------------
-- Table `DialogueFlowDB`.`Status`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DialogueFlowDB`.`Status` (
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `Status` CHAR(255) NOT NULL,
  PRIMARY KEY (`ID`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DialogueFlowDB`.`MultiStep_Dialogues`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DialogueFlowDB`.`MultiStep_Dialogues` (
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `MultiStep_Dialogue` CHAR(255) NOT NULL,
  `Data_Items` VARCHAR(1000) NULL,
  `Nodes` VARCHAR(1000) NULL,
  `Node_Links` VARCHAR(1000) NULL,
  `Comments` VARCHAR(1000) NULL,
  `Status` INT UNSIGNED NOT NULL,
  `Issue` INT NOT NULL,
  `LO_Name` CHAR(255) NULL,
  `LO_Description` CHAR(255) NULL,
  `LO_Condition` VARCHAR(1000) NULL,
  `LO_Variables` VARCHAR(1000) NULL,
  `LO_List` INT NULL,
  PRIMARY KEY (`ID`),
  INDEX `fk_MultiStep_Dialogues_Status1_idx` (`Status` ASC) VISIBLE,
  CONSTRAINT `fk_MultiStep_Dialogues_Status1`
    FOREIGN KEY (`Status`)
    REFERENCES `DialogueFlowDB`.`Status` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DialogueFlowDB`.`Node_Types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DialogueFlowDB`.`Node_Types` (
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `Node_Type` CHAR(255) NOT NULL,
  PRIMARY KEY (`ID`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DialogueFlowDB`.`Variables`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DialogueFlowDB`.`Variables` (
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `Variable` CHAR(255) NOT NULL,
  `Variable_ID` CHAR(255) NOT NULL,
  `System_Variable` CHAR(255) NULL,
  `Values_per_Item` ENUM('Single', 'Multiple') NOT NULL DEFAULT 'Single',
  `MultiStep_Dialogue` INT UNSIGNED NOT NULL,
  `Input_Values` VARCHAR(1000) NULL,
  `Comments` VARCHAR(1000) NULL,
  PRIMARY KEY (`ID`),
  INDEX `fk_Variables_MultiStep_Dialogues1_idx` (`MultiStep_Dialogue` ASC) VISIBLE,
  CONSTRAINT `fk_Variables_MultiStep_Dialogues1`
    FOREIGN KEY (`MultiStep_Dialogue`)
    REFERENCES `DialogueFlowDB`.`MultiStep_Dialogues` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DialogueFlowDB`.`Nodes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DialogueFlowDB`.`Nodes` (
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `Node` CHAR(255) NOT NULL,
  `Node_ID` CHAR(255) NOT NULL,
  `Node_Sequence` ENUM('End', 'Middle', 'Start') NOT NULL,
  `Node_Type` INT UNSIGNED NOT NULL,
  `XPosition` INT NOT NULL DEFAULT 0,
  `YPosition` INT NOT NULL DEFAULT 0,
  `Answer` VARCHAR(1000) NOT NULL,
  `Data_Item` INT UNSIGNED NULL,
  `Status` INT UNSIGNED NOT NULL DEFAULT 'Created',
  `MultiStep_Dialogue` INT UNSIGNED NOT NULL,
  `Comments` VARCHAR(1000) NULL,
  `Previous_Node_Links` VARCHAR(1000) NULL,
  `Next_Node_Link` VARCHAR(100) NULL,
  PRIMARY KEY (`ID`),
  INDEX `fk_Nodes_MultiStep_Dialogues_idx` (`MultiStep_Dialogue` ASC) VISIBLE,
  INDEX `fk_Nodes_Node_Types1_idx` (`Node_Type` ASC) VISIBLE,
  INDEX `fk_Nodes_Variables1_idx` (`Data_Item` ASC) VISIBLE,
  INDEX `fk_Nodes_Status1_idx` (`Status` ASC) VISIBLE,
  CONSTRAINT `fk_Nodes_MultiStep_Dialogues`
    FOREIGN KEY (`MultiStep_Dialogue`)
    REFERENCES `DialogueFlowDB`.`MultiStep_Dialogues` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Nodes_Node_Types1`
    FOREIGN KEY (`Node_Type`)
    REFERENCES `DialogueFlowDB`.`Node_Types` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Nodes_Status1`
    FOREIGN KEY (`Status`)
    REFERENCES `DialogueFlowDB`.`Status` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Nodes_Variables1`
    FOREIGN KEY (`Data_Item`)
    REFERENCES `DialogueFlowDB`.`Variables` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DialogueFlowDB`.`Node_Links`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DialogueFlowDB`.`Node_Links` (
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `Node_Link` CHAR(255) NOT NULL,
  `MultiStep_Dialogue` INT UNSIGNED NOT NULL,
  `From_Node` INT UNSIGNED NOT NULL,
  `To_Node` INT UNSIGNED NOT NULL,
  `Status` INT UNSIGNED NOT NULL,
  `Comments` VARCHAR(1000) NULL,
  PRIMARY KEY (`ID`),
  INDEX `fk_Node_Links_Nodes1_idx` (`From_Node` ASC) VISIBLE,
  INDEX `fk_Node_Links_MultiStep_Dialogues1_idx` (`MultiStep_Dialogue` ASC) VISIBLE,
  INDEX `fk_Node_Links_Nodes2_idx` (`To_Node` ASC) VISIBLE,
  INDEX `fk_Node_Links_Status1_idx` (`Status` ASC) VISIBLE,
  CONSTRAINT `fk_Node_Links_Nodes1`
    FOREIGN KEY (`From_Node`)
    REFERENCES `DialogueFlowDB`.`Nodes` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Node_Links_MultiStep_Dialogues1`
    FOREIGN KEY (`MultiStep_Dialogue`)
    REFERENCES `DialogueFlowDB`.`MultiStep_Dialogues` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Node_Links_Nodes2`
    FOREIGN KEY (`To_Node`)
    REFERENCES `DialogueFlowDB`.`Nodes` (`ID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Node_Links_Status1`
    FOREIGN KEY (`Status`)
    REFERENCES `DialogueFlowDB`.`Status` (`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 MariaDB server version for the right syntax to use near '
  CONSTRAINT `fk_MultiStep_Dialogues_Status1`
    FOREIGN KEY (`Status`)
    RE' at line 19
SQL Code:
        -- -----------------------------------------------------
        -- Table `DialogueFlowDB`.`MultiStep_Dialogues`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `DialogueFlowDB`.`MultiStep_Dialogues` (
          `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
          `MultiStep_Dialogue` CHAR(255) NOT NULL,
          `Data_Items` VARCHAR(1000) NULL,
          `Nodes` VARCHAR(1000) NULL,
          `Node_Links` VARCHAR(1000) NULL,
          `Comments` VARCHAR(1000) NULL,
          `Status` INT UNSIGNED NOT NULL,
          `Issue` INT NOT NULL,
          `LO_Name` CHAR(255) NULL,
          `LO_Description` CHAR(255) NULL,
          `LO_Condition` VARCHAR(1000) NULL,
          `LO_Variables` VARCHAR(1000) NULL,
          `LO_List` INT NULL,
          PRIMARY KEY (`ID`),
          INDEX `fk_MultiStep_Dialogues_Status1_idx` (`Status` ASC) VISIBLE,
          CONSTRAINT `fk_MultiStep_Dialogues_Status1`
            FOREIGN KEY (`Status`)
            REFERENCES `DialogueFlowDB`.`Status` (`ID`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION)
        ENGINE = InnoDB

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

Fetching back view definitions in final form.
Nothing to fetch

我在网上看到,问题可能与外键有关(尽管我检查过了,看起来不错……),或者与engine=innodb声明有关。我试着用这个问题的答案,但没有成功,或者我不太明白答案(我交换了engine=innodb;使用engine=innodb default charset=utf8 collate=utf8\u unicode\u ci;)我还检查了我的mysql版本,我使用10.1.35-mariadb,它应该有不可见的索引可用(如我链接的问题的另一个答案所述)。
我没有mysql的经验,所以如果这是一个非常简单的问题,我很抱歉。感谢您的帮助:)

ep6jt1vc

ep6jt1vc1#

好吧,有两个不同的问题。dialogueflow表中无符号int“status”的默认值是“created”(我从使用枚举改为使用外键,忘记删除旧的默认值),所以 Status int unsigned not null默认值“created”
另一个问题似乎与索引有关。当移除所有组件时:
索引 fk_MultiStep_Dialogues_Status1_idx ( Status asc)可见
索引 fk_Nodes_MultiStep_Dialogues_idx ( MultiStep_Dialogue asc)可见,
索引 fk_Nodes_Node_Types1_idx ( Node_Type asc)可见,
诸如此类,似乎奏效了。我真的不明白为什么会这样,但现在我将删除外键上的索引,并在以后修复它。

相关问题