带有外键的 MariaDB 表创建错误

这样的问题有很多,但我在其中找不到答案.

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

你能告诉我这里有什么问题吗?该脚本是由 mysql Workbench 创建的,但除了答案之外它没有

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;

给定的错误是

错误代码:1064.您的 SQL 语法有错误;检查手册
对应于您的 MariaDB 服务器版本,以便使用正确的语法靠近 ' CONSTRAINT fk_Account_Owner FOREIGN KEY (OwnerId)
参考第 7 行的myd"

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

推荐答案

又一个需要去掉VISIBLE这个词的案例.

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

相关文章