1064-您的sql语法有错误;请查看与mysql服务器版本对应的手册,以获得使用“visible,constraint”附近的正确语法 fk_TeamStatistik_Team
外键( Team_id
)'第10行
我使用mysql workbench创建了数据库,出现了这个错误,下面我发布了mysql workbench生成的sql代码…我在phpmyadmin中输入sql代码时出现了这个错误。有人能帮忙吗?提前谢谢。
-- MySQL Script generated by MySQL Workbench
-- Sun Oct 21 14:37:37 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 dbpws18db16
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema dbpws18db16
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `dbpws18db16` DEFAULT CHARACTER SET utf8 ;
USE `dbpws18db16` ;
-- -----------------------------------------------------
-- Table `dbpws18db16`.`Team`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `dbpws18db16`.`Team` ;
CREATE TABLE IF NOT EXISTS `dbpws18db16`.`Team` (
`id` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) NULL,
`Stadt` VARCHAR(45) NULL,
`Staat` VARCHAR(45) NULL,
`Besitzer` VARCHAR(45) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `dbpws18db16`.`Spieler`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `dbpws18db16`.`Spieler` ;
CREATE TABLE IF NOT EXISTS `dbpws18db16`.`Spieler` (
`id` INT NOT NULL AUTO_INCREMENT,
`Alter` INT NULL,
`Vorname` VARCHAR(45) NULL,
`Nachname` VARCHAR(45) NULL,
`Position` VARCHAR(45) NULL,
`Größe` DECIMAL NULL,
`Team_id` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_Spieler_Team1_idx` (`Team_id` ASC) VISIBLE,
CONSTRAINT `fk_Spieler_Team1`
FOREIGN KEY (`Team_id`)
REFERENCES `dbpws18db16`.`Team` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `dbpws18db16`.`Individuelle Statistik`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `dbpws18db16`.`Individuelle Statistik` ;
CREATE TABLE IF NOT EXISTS `dbpws18db16`.`Individuelle Statistik` (
`id` INT NOT NULL AUTO_INCREMENT,
`PPG` VARCHAR(45) NULL,
`RPG` VARCHAR(45) NULL,
`SPG` VARCHAR(45) NULL,
`APG` VARCHAR(45) NULL,
`GP` VARCHAR(45) NULL,
`BPG` VARCHAR(45) NULL,
`FG` INT NULL,
`Spieler_id` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_Individuelle Statistik_Spieler1_idx` (`Spieler_id` ASC) VISIBLE,
CONSTRAINT `fk_Individuelle Statistik_Spieler1`
FOREIGN KEY (`Spieler_id`)
REFERENCES `dbpws18db16`.`Spieler` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `dbpws18db16`.`Saison`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `dbpws18db16`.`Saison` ;
CREATE TABLE IF NOT EXISTS `dbpws18db16`.`Saison` (
`id` INT NOT NULL AUTO_INCREMENT,
`Beginn` DATETIME NULL,
`Ende` DATETIME NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `dbpws18db16`.`Spiele`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `dbpws18db16`.`Spiele` ;
CREATE TABLE IF NOT EXISTS `dbpws18db16`.`Spiele` (
`id` INT NOT NULL AUTO_INCREMENT,
`hd` VARCHAR(45) NULL,
`Spielecol` VARCHAR(45) NULL,
`Saison_id` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_Spiele_Saison1_idx` (`Saison_id` ASC) VISIBLE,
CONSTRAINT `fk_Spiele_Saison1`
FOREIGN KEY (`Saison_id`)
REFERENCES `dbpws18db16`.`Saison` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `dbpws18db16`.`TeamStatistik`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `dbpws18db16`.`TeamStatistik` ;
CREATE TABLE IF NOT EXISTS `dbpws18db16`.`TeamStatistik` (
`id` INT NOT NULL AUTO_INCREMENT,
`BPG` DECIMAL NULL,
`APG` DECIMAL NULL,
`SPG` DECIMAL NULL,
`GP` INT NULL,
`PPG` DECIMAL NULL,
`RPG` DECIMAL NULL,
`Team_id` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_TeamStatistik_Team_idx` (`Team_id` ASC) VISIBLE,
CONSTRAINT `fk_TeamStatistik_Team`
FOREIGN KEY (`Team_id`)
REFERENCES `dbpws18db16`.`Team` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `dbpws18db16`.`Team_has_Spiele`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `dbpws18db16`.`Team_has_Spiele` ;
CREATE TABLE IF NOT EXISTS `dbpws18db16`.`Team_has_Spiele` (
`Team_id` INT NOT NULL,
`Spiele_id` INT NOT NULL,
PRIMARY KEY (`Team_id`, `Spiele_id`),
INDEX `fk_Team_has_Spiele_Spiele1_idx` (`Spiele_id` ASC) VISIBLE,
INDEX `fk_Team_has_Spiele_Team1_idx` (`Team_id` ASC) VISIBLE,
CONSTRAINT `fk_Team_has_Spiele_Team1`
FOREIGN KEY (`Team_id`)
REFERENCES `dbpws18db16`.`Team` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Team_has_Spiele_Spiele1`
FOREIGN KEY (`Spiele_id`)
REFERENCES `dbpws18db16`.`Spiele` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
-- -----------------------------------------------------
-- Data for table `dbpws18db16`.`Team`
-- -----------------------------------------------------
START TRANSACTION;
USE `dbpws18db16`;
INSERT INTO `dbpws18db16`.`Team` (`id`, `Name`, `Stadt`, `Staat`, `Besitzer`) VALUES (1, 'abc', 'cf', 'dd', 'ddd');
COMMIT;
-- -----------------------------------------------------
-- Data for table `dbpws18db16`.`Spieler`
-- -----------------------------------------------------
START TRANSACTION;
USE `dbpws18db16`;
INSERT INTO `dbpws18db16`.`Spieler` (`id`, `Alter`, `Vorname`, `Nachname`, `Position`, `Größe`, `Team_id`) VALUES (1, 12, 'cdcrc', 'crcr', 'crc', 1.89, DEFAULT);
COMMIT;
-- -----------------------------------------------------
-- Data for table `dbpws18db16`.`Individuelle Statistik`
-- -----------------------------------------------------
START TRANSACTION;
USE `dbpws18db16`;
INSERT INTO `dbpws18db16`.`Individuelle Statistik` (`id`, `PPG`, `RPG`, `SPG`, `APG`, `GP`, `BPG`, `FG`, `Spieler_id`) VALUES (1, '2', '2', '2', '2', '2', NULL, NULL, DEFAULT);
COMMIT;
-- -----------------------------------------------------
-- Data for table `dbpws18db16`.`Saison`
-- -----------------------------------------------------
START TRANSACTION;
USE `dbpws18db16`;
INSERT INTO `dbpws18db16`.`Saison` (`id`, `Beginn`, `Ende`) VALUES (1, '01.04.2018', '01.04.2019');
COMMIT;
-- -----------------------------------------------------
-- Data for table `dbpws18db16`.`Spiele`
-- -----------------------------------------------------
START TRANSACTION;
USE `dbpws18db16`;
INSERT INTO `dbpws18db16`.`Spiele` (`id`, `hd`, `Spielecol`, `Saison_id`) VALUES (1, 'dw', 'de', DEFAULT);
INSERT INTO `dbpws18db16`.`Spiele` (`id`, `hd`, `Spielecol`, `Saison_id`) VALUES (, NULL, NULL, DEFAULT);
COMMIT;
-- -----------------------------------------------------
-- Data for table `dbpws18db16`.`TeamStatistik`
-- -----------------------------------------------------
START TRANSACTION;
USE `dbpws18db16`;
INSERT INTO `dbpws18db16`.`TeamStatistik` (`id`, `BPG`, `APG`, `SPG`, `GP`, `PPG`, `RPG`, `Team_id`) VALUES (1, 2.3, 2.2., 2.2, 2.2, 2.2, 2.2, DEFAULT);
INSERT INTO `dbpws18db16`.`TeamStatistik` (`id`, `BPG`, `APG`, `SPG`, `GP`, `PPG`, `RPG`, `Team_id`) VALUES (2, 3, 4, 3, 4, 4, 4, DEFAULT);
COMMIT;
2条答案
按热度按时间bvuwiixz1#
mysql workbench允许您设置在生成模式时使用的mysql目标版本。
编辑/preferences/modeling/mysql/将*default target mysql version“设置为
5.5.60
.当它为您生成sql时,它将避免使用新的版本8特性。
6g8kf2rb2#
这里的问题是不同mysql服务器版本的语法不同。您的mysql workbench版本似乎是8.0及更高版本。它自动生成的代码适用于mysql server版本8.0。
您需要将mysql服务器版本升级到8.0或更高版本。或者,您可以删除
VISIBLE
来自所有位置(定义索引的位置)的关键字,如下所示:到
您还需要在查询的其他部分执行相同的操作。
其他详细信息
在mysql server 8.0文档中
CREATE INDEX
是:然而,这种选择
{VISIBLE | INVISIBLE}
在mysql server 5.5(您的服务器版本)中不可用。来自文档: