带有外键的 MariaDB 表创建错误

MariaDB Table Creation Error with Foreign Key(带有外键的 MariaDB 表创建错误)
本文介绍了带有外键的 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.

这篇关于带有外键的 MariaDB 表创建错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)