有人能告诉我为什么在正向工程时我会在 mysql workbench 中收到这个错误吗?
Can someone tell my why am i getting this error in mysql workbench while forward engineering?
我创建了学生管理系统的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
有人可以告诉我错误在哪里以及如何解决吗?
问题出在 PRIMARY KEY
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)
我创建了学生管理系统的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
有人可以告诉我错误在哪里以及如何解决吗?
问题出在 PRIMARY KEY
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)