1

There are many questions like that but I cannot find my answer among them.

Can you tell me what is wrong here? The script was created by mysql Workbench but it does not except the answer

-- MySQL Script generated by MySQL Workbench
-- Mon Nov 26 14:14:46 2018
-- Model: New Model    Version: 1.0
-- 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 mydb
-- -----------------------------------------------------

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

-- -----------------------------------------------------
-- Table `mydb`.`Owner`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Owner` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Owner` (
  `OwnerId` CHAR(36) NOT NULL,
  `Name` NVARCHAR(60) NOT NULL,
  `DateOfBirth` DATE NOT NULL,
  `Adress` NVARCHAR(100) NOT NULL,
  PRIMARY KEY (`OwnerId`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Account`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Account` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Account` (
  `AccountId` CHAR(36) NOT NULL,
  `DateCreated` DATE NOT NULL,
  `AccountType` VARCHAR(45) NOT NULL,
  `OwnerId` CHAR(36) NULL,
  PRIMARY KEY (`AccountId`),
  INDEX `fk_Account_Owner_idx` (`OwnerId` ASC) VISIBLE,
  CONSTRAINT `fk_Account_Owner`
    FOREIGN KEY (`OwnerId`)
    REFERENCES `mydb`.`Owner` (`OwnerId`)
    ON DELETE RESTRICT
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

The given error is

Error Code: 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_Account_Owner FOREIGN KEY (OwnerId)
REFERENCES `myd' at line 7

3

2 Answers 2

2

Yet another case of needing to get rid of the word VISIBLE.

Sign up to request clarification or add additional context in comments.

3 Comments

but the workbench created that script isn't it supposed to be correct ?? I am trying what you wrote now.
Actually, it's not the VISIBLE keyword, which is the true culprit, but the server version which is set for modeling (see model preferences).
@Johnyy66554 - Workbench is built by Oracle, and the latest version is aimed for the latest version of MySQL (8.0), which has a new keyword VISIBLE. Since Workbench seems to want to aggressively include that word, it causes errors in all older versions of MySQL, and all versions of MariaDB. This forum is being littered with the problem.
1

In MySQL Workbench:

Go to:

Edit > Preferences > Modeling > MySQL.

Then, set the "Default Target MySQL Version" to 5.7

from https://stackoverflow.com/a/52785302/2625955

1 Comment

Tried that but did not help. Still exactly the same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.