MariaDB Table Creation Error with Foreign Key

风流意气都作罢 提交于 2020-01-25 03:06:41

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/53480613/mariadb-table-creation-error-with-foreign-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!