所以我试图将我在Workbench6.2上创建的数据库部署到一个真实的数据库(以测试它)。
但每次我部署它时都会不断地出现错误,每次我想我已经解决了这个问题,就会弹出一些其他的错误消息(这次是1064)。
有谁能帮我弄一下我的数据库,这样我就可以最终部署它并进行测试了吗?(我是个笨蛋,所以请对我耐心点)……
这正是Forward Engineering试图执行的:

-- 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='TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema iPlanner
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema iPlanner
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `iPlanner` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `iPlanner` ;

-- -----------------------------------------------------
-- Table `iPlanner`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iPlanner`.`users` (
  `user_permission` INT NOT NULL,
  `user_login` VARCHAR(45) NULL,
  `user_pass` VARCHAR(45) NULL,
  `pass_attempts` INT NULL,
  `user_f_name` VARCHAR(45) NULL,
  `user_l_name` VARCHAR(45) NULL,
  `user_email` VARCHAR(75) NULL,
  PRIMARY KEY (`user_permission`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `iPlanner`.`administrators`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iPlanner`.`administrators` (
  `admin_id` INT NOT NULL AUTO_INCREMENT,
  `user_permission` INT NULL,
  PRIMARY KEY (`admin_id`),
  INDEX `user_permission_idx` (`user_permission` ASC),
  CONSTRAINT `user_permission`
    FOREIGN KEY (`user_permission`)
    REFERENCES `iPlanner`.`users` (`user_permission`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_login`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_pass`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `pass_attempts`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_f_name`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_l_name`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_email`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `iPlanner`.`schools`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iPlanner`.`schools` (
  `school_id` INT NOT NULL AUTO_INCREMENT,
  `school_name` VARCHAR(45) NULL,
  `school_city` VARCHAR(75) NULL,
  `school_state` VARCHAR(2) NULL,
  `school_zipcode` VARCHAR(45) NULL,
  `principal_id` INT NOT NULL,
  PRIMARY KEY (`school_id`),
  INDEX `principal_id_idx` (`principal_id` ASC),
  CONSTRAINT `principal_id`
    FOREIGN KEY (`principal_id`)
    REFERENCES `iPlanner`.`administrators` (`admin_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `iPlanner`.`subject`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iPlanner`.`subject` (
  `subject_id` INT NOT NULL AUTO_INCREMENT,
  `subject_name` VARCHAR(45) NULL,
  `teacher_id` INT NOT NULL,
  PRIMARY KEY (`subject_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `iPlanner`.`class`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iPlanner`.`class` (
  `class_id` INT NOT NULL,
  `subject_id` INT NOT NULL,
  `class_name` VARCHAR(75) NULL,
  PRIMARY KEY (`class_id`),
  INDEX `subject_id_idx` (`subject_id` ASC),
  CONSTRAINT `subject_id`
    FOREIGN KEY (`subject_id`)
    REFERENCES `iPlanner`.`subject` (`subject_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `iPlanner`.`teachers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iPlanner`.`teachers` (
  `teacher_id` INT NOT NULL AUTO_INCREMENT,
  `user_permission` INT NULL,
  PRIMARY KEY (`teacher_id`),
  INDEX `user_permission_idx` (`user_permission` ASC),
  CONSTRAINT `user_permission`
    FOREIGN KEY (`user_permission`)
    REFERENCES `iPlanner`.`users` (`user_permission`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_login`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_pass`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `pass_attempts`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_f_name`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_l_name`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_email`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `iPlanner`.`subject_class`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iPlanner`.`subject_class` (
  `sc_id` INT NOT NULL AUTO_INCREMENT,
  `class_id` INT NOT NULL,
  `subject_id` INT NOT NULL,
  `teacher_id` INT NOT NULL,
  PRIMARY KEY (`sc_id`),
  INDEX `class_id_idx` (`class_id` ASC),
  INDEX `subject_id_idx` (`subject_id` ASC),
  INDEX `teacher_id_idx` (`teacher_id` ASC),
  CONSTRAINT `class_id`
    FOREIGN KEY (`class_id`)
    REFERENCES `iPlanner`.`class` (`class_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `subject_id`
    FOREIGN KEY (`subject_id`)
    REFERENCES `iPlanner`.`subject` (`subject_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `teacher_id`
    FOREIGN KEY (`teacher_id`)
    REFERENCES `iPlanner`.`teachers` (`teacher_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `iPlanner`.`students`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iPlanner`.`students` (
  `student_id` INT NOT NULL AUTO_INCREMENT,
  `user_permission` INT NULL,
  `signature` VARCHAR(150) NULL,
  PRIMARY KEY (`student_id`),
  INDEX `user_permission_idx` (`user_permission` ASC),
  CONSTRAINT `user_permission`
    FOREIGN KEY (`user_permission`)
    REFERENCES `iPlanner`.`users` (`user_permission`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_login`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_pass`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `pass_attempts`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_f_name`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_l_name`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `user_email`
    FOREIGN KEY ()
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `iPlanner`.`enrollment`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iPlanner`.`enrollment` (
  `enrollment_id` INT NOT NULL AUTO_INCREMENT,
  `subject_class_id` INT NOT NULL,
  `student_id` INT NOT NULL,
  PRIMARY KEY (`enrollment_id`),
  INDEX `subject_class_id_idx` (`subject_class_id` ASC),
  INDEX `student_id_idx` (`student_id` ASC),
  CONSTRAINT `subject_class_id`
    FOREIGN KEY (`subject_class_id`)
    REFERENCES `iPlanner`.`subject_class` (`sc_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `student_id`
    FOREIGN KEY (`student_id`)
    REFERENCES `iPlanner`.`students` (`student_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `iPlanner`.`assignments`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iPlanner`.`assignments` (
  `assignment_id` INT NOT NULL AUTO_INCREMENT,
  `assignment_content` VARCHAR(45) NULL,
  `assignment_due_date` VARCHAR(45) NULL,
  `assignment_date` VARCHAR(45) NULL,
  `assignment_time` VARCHAR(45) NULL,
  `subject_class_id` INT NOT NULL,
  PRIMARY KEY (`assignment_id`),
  INDEX `subject_class_id_idx` (`subject_class_id` ASC),
  CONSTRAINT `subject_class_id`
    FOREIGN KEY (`subject_class_id`)
    REFERENCES `iPlanner`.`subject_class` (`sc_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `iPlanner`.`submits`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `iPlanner`.`submits` (
  `submit_id` INT NOT NULL AUTO_INCREMENT,
  `student_id` INT NOT NULL,
  `assignment_id` INT NOT NULL,
  `notes_teacher` VARCHAR(45) NULL,
  `notes_parents` VARCHAR(45) NULL,
  `parent_signature` VARCHAR(45) NULL,
  `total_time` VARCHAR(45) NULL,
  PRIMARY KEY (`submit_id`),
  INDEX `assignment_id_idx` (`assignment_id` ASC),
  INDEX `student_id_idx` (`student_id` ASC),
  CONSTRAINT `assignment_id`
    FOREIGN KEY (`assignment_id`)
    REFERENCES `iPlanner`.`assignments` (`assignment_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `student_id`
    FOREIGN KEY (`student_id`)
    REFERENCES `iPlanner`.`students` (`student_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;

这就是我现在犯的错误。
Executing SQL script in server
ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ' at line 12
SQL Code:
        CREATE TABLE IF NOT EXISTS `iPlanner`.`administrators` (
          `admin_id` INT NOT NULL AUTO_INCREMENT,
          `user_permission` INT NULL,
          PRIMARY KEY (`admin_id`),
          INDEX `user_permission_idx` (`user_permission` ASC),
          CONSTRAINT `user_permission`
            FOREIGN KEY (`user_permission`)
            REFERENCES `iPlanner`.`users` (`user_permission`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `user_login`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `user_pass`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `pass_attempts`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `user_f_name`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `user_l_name`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `user_email`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION)
        ENGINE = InnoDB

SQL script execution finished: statements: 8 succeeded, 1 failed

Fetching back view definitions in final form.
Nothing to fetch
Executing SQL script in server
ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
    REFERENCES `iPlanner`.`users` ()
    ON DELETE NO ACTION
    ON UPDATE NO ' at line 15
SQL Code:
        -- -----------------------------------------------------
        -- Table `iPlanner`.`administrators`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `iPlanner`.`administrators` (
          `admin_id` INT NOT NULL AUTO_INCREMENT,
          `user_permission` INT NULL,
          PRIMARY KEY (`admin_id`),
          INDEX `user_permission_idx` (`user_permission` ASC),
          CONSTRAINT `user_permission`
            FOREIGN KEY (`user_permission`)
            REFERENCES `iPlanner`.`users` (`user_permission`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `user_login`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `user_pass`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `pass_attempts`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `user_f_name`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `user_l_name`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `user_email`
            FOREIGN KEY ()
            REFERENCES `iPlanner`.`users` ()
            ON DELETE NO ACTION
            ON UPDATE NO ACTION)
        ENGINE = InnoDB

SQL script execution finished: statements: 6 succeeded, 1 failed

Fetching back view definitions in final form.
Nothing to fetch

最佳答案

edit 1064的意思是“语法错误”,如果你在运行由类似workbench的工具创建的sql时发现了这个问题,那就意味着这个工具有一个bug或者你用错了它。
当mysql检测到错误时,它会显示单词for the right syntax to use near,然后显示一些查询,从查询中第一个不理解的字符开始。这有助于你找出问题所在。
在你的问题中,这是一个右括号。对我来说,这意味着它希望在REFERENCES子句的括号之间出现一些东西。
在我看来,您的模型的administrators表有许多格式错误的外键返回到users表。
这里只有一个。

     CONSTRAINT `user_login`
        FOREIGN KEY ()
        REFERENCES `iPlanner`.`users` ()
        ON DELETE NO ACTION
        ON UPDATE NO ACTION,

注意():它引用的是表,但没有列。

10-06 03:11