programing

MySQL에서 Forward Engineering을 시도하는 동안 오류 1064가 발생했습니다.

lovejava 2023. 8. 17. 20:31

MySQL에서 Forward Engineering을 시도하는 동안 오류 1064가 발생했습니다.

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이 처음이라 어떤 문제가 발생할 수 있는지 전혀 모르겠습니다.

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

언급URL : https://stackoverflow.com/questions/61369892/error-1064-in-mysql-trying-forward-engineering