在MySQL中尝试Forward Engineering时出错1064

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在MySQL中尝试Forward Engineering时出错1064相关的知识,希望对你有一定的参考价值。

我是mysql的新手,当我想做 "前进工程师 "的时候,遇到了这个错误。

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新手,我也不知道会是什么问题导致的

答案

就目前来看,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

以上是关于在MySQL中尝试Forward Engineering时出错1064的主要内容,如果未能解决你的问题,请参考以下文章

1.使用Entity Framwork框架常用的技术手段Code First 和Reverse Engineer Code First

sql Wave Transcript Report with Engineer Engineer Details

[远程] 秘猿科技 招聘 Senior Performance Engineer...

HW职责 (Hardware Engineer)

Linux学习之Engineer

HDU 6006 Engineer Assignment:状压dp