【问题标题】:Can someone tell my why am i getting this error in mysql workbench while forward engineering?有人可以告诉我为什么我在正向工程时在 mysql 工作台中收到此错误吗?
【发布时间】:2016-05-26 14:06:49
【问题描述】:

我为学生管理系统创建了 ER 图,然后单击正向工程并完成对话框中的步骤。但它显示了这样的错误消息。

   Executing SQL script in server
   ERROR: Error 1075: Incorrect table definition; there can be only one auto column and it must be defined as a key
 SQL Code:
    -- -----------------------------------------------------
    -- Table `SLIOP`.`course`
    -- -----------------------------------------------------
    CREATE TABLE IF NOT EXISTS `SLIOP`.`course` (
      `courseNo` INT NOT NULL AUTO_INCREMENT,
      `courseID` VARCHAR(10) NOT NULL,
      `course_name` VARCHAR(40) NOT NULL,
      `course_type` VARCHAR(25) NOT NULL,
      `content_type` VARCHAR(20) NOT NULL,
      `lecturer_name` VARCHAR(40) NOT NULL,
      `time` TIMESTAMP NOT NULL,
      `fee` DECIMAL(10,2) NOT NULL,
      `no_classes` INT NOT NULL,
      `no_students` INT NOT NULL,
      `requirement` MEDIUMTEXT NOT NULL,
      `lecturerID` INT NOT NULL,
      PRIMARY KEY (`courseID`),
      INDEX `fk_course_academic_staff1_idx` (`lecturerID` ASC),
      CONSTRAINT `fk_course_academic_staff1`
        FOREIGN KEY (`lecturerID`)
        REFERENCES `SLIOP`.`academic_staff` (`lecturerID`)
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB

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

    Fetching back view definitions in final form.
    Nothing to fetch

谁能告诉我错误在哪里以及如何解决?

【问题讨论】:

    标签: mysql mysql-workbench mysql-error-1064


    【解决方案1】:

    问题出在主键上

    CREATE TABLE IF NOT EXISTS `SLIOP`.`course` (
      `courseNo` INT NOT NULL AUTO_INCREMENT,
      `courseID` VARCHAR(10) NOT NULL,
      `course_name` VARCHAR(40) NOT NULL,
      `course_type` VARCHAR(25) NOT NULL,
      `content_type` VARCHAR(20) NOT NULL,
      `lecturer_name` VARCHAR(40) NOT NULL,
      `time` TIMESTAMP NOT NULL,
      `fee` DECIMAL(10,2) NOT NULL,
      `no_classes` INT NOT NULL,
      `no_students` INT NOT NULL,
      `requirement` MEDIUMTEXT NOT NULL,
      `lecturerID` INT NOT NULL,
      PRIMARY KEY (`courseNo`),
      INDEX `fk_course_academic_staff1_idx` (`lecturerID` ASC),
      CONSTRAINT `fk_course_academic_staff1`
        FOREIGN KEY (`lecturerID`)
        REFERENCES `SLIOP`.`academic_staff` (`lecturerID`)
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-30
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 2012-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多