【问题标题】:Error 1064 in MySQL trying Forward EngineeringMySQL 尝试正向工程时出现错误 1064
【发布时间】:2020-08-05 18:07:37
【问题描述】:

我是 MySQL 新手,当我尝试执行“Forward Engineer”时遇到了这个错误:

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_Vendite_Prodotti`
    FOREIGN KEY (`Prodotti_idProdotti`)
    ' at line 11
SQL Code:
        -- -----------------------------------------------------
        -- Table `mydb`.`Vendite`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `mydb`.`Vendite` (
          `idVendite` INT NOT NULL,
          `dataVendita` DATETIME NULL,
          `qta` INT NULL,
          `costo` FLOAT NULL,
          `Prodotti_idProdotti` INT NOT NULL,
          PRIMARY KEY (`idVendite`),
          INDEX `fk_Vendite_Prodotti_idx` (`Prodotti_idProdotti` ASC) VISIBLE,
          CONSTRAINT `fk_Vendite_Prodotti`
            FOREIGN KEY (`Prodotti_idProdotti`)
            REFERENCES `mydb`.`Prodotti` (`idProdotti`)
            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

我知道有很多关于这个主题的问题,但我看到它是一个非常具体的问题。同样是 SQL 新手,我不知道问题可能是什么

【问题讨论】:

    标签: mysql sql syntax mariadb create-table


    【解决方案1】:

    就问题而言,MariaDB 不支持不可见索引(只有 MySQL 8.0 支持),因此错误来自使用 VISIBLE 关键字。

    由于默认情况下索引是可见的,我建议将其删除:

    CREATE TABLE IF NOT EXISTS `mydb`.`Vendite` (
          `idVendite` INT NOT NULL,
          `dataVendita` DATETIME NULL,
          `qta` INT NULL,
          `costo` FLOAT NULL,
          `Prodotti_idProdotti` INT NOT NULL,
          PRIMARY KEY (`idVendite`),
          INDEX `fk_Vendite_Prodotti_idx` (`Prodotti_idProdotti`),
          CONSTRAINT `fk_Vendite_Prodotti`
            FOREIGN KEY (`Prodotti_idProdotti`)
            REFERENCES `mydb`.`Prodotti` (`idProdotti`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION
    ) ENGINE = InnoDB
    

    【讨论】:

      猜你喜欢
      • 2019-05-04
      • 1970-01-01
      • 2019-03-08
      • 2019-03-11
      • 1970-01-01
      • 2013-10-18
      • 2018-04-18
      • 1970-01-01
      • 2015-10-09
      相关资源
      最近更新 更多