简体   繁体   中英

MySQL Workbench Database error

I created a Database with Mysql Qorkbench and i tried to Forward Engineer to Database but it completed with errors and this is the Message Log:

> Executing SQL script in server
ERROR: Error 1005: Can't create table `mydb`.`cds` (errno: 121 "Duplicate key on write or update")
SQL Code:
        -- -----------------------------------------------------
        -- Table `mydb`.`CDs`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `mydb`.`CDs` (
          `CDid` INT NOT NULL AUTO_INCREMENT,
          `Titel` VARCHAR(45) NOT NULL,
          `Autor` VARCHAR(45) NOT NULL,
          `Erscheinungsjahr` VARCHAR(45) NOT NULL,
          `Genre` VARCHAR(45) NOT NULL,
          `Stockwerk` VARCHAR(45) NOT NULL,
          `Regal` INT NOT NULL,
          `Ausgeborgt` INT NULL,
          `Rezensionen` VARCHAR(600) NULL,
          `Kurzbeschreibung` VARCHAR(600) NOT NULL,
          PRIMARY KEY (`CDid`),
          UNIQUE INDEX `CDid_UNIQUE` (`CDid` ASC),
          INDEX `Buchungsid_idx` (`Ausgeborgt` ASC),
          CONSTRAINT `Buchungsid`
            FOREIGN KEY (`Ausgeborgt`)
            REFERENCES `mydb`.`Buchung` (`Buchungsid`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION)
        ENGINE = InnoDB

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

Fetching back view definitions in final form.
Could not get definition for mydb.view1 from server
1 views were read back.

This is the EER Diagram of my Database

A primary key is essentially an indexed unique not null constraint. You don't need to add an additional unique constraint, and indeed can't, as the error specifies. Remove the extra unique index clause and you should be OK:

CREATE TABLE IF NOT EXISTS `mydb`.`CDs` (
  `CDid` INT NOT NULL AUTO_INCREMENT,
  `Titel` VARCHAR(45) NOT NULL,
  `Autor` VARCHAR(45) NOT NULL,
  `Erscheinungsjahr` VARCHAR(45) NOT NULL,
  `Genre` VARCHAR(45) NOT NULL,
  `Stockwerk` VARCHAR(45) NOT NULL,
  `Regal` INT NOT NULL,
  `Ausgeborgt` INT NULL,
  `Rezensionen` VARCHAR(600) NULL,
  `Kurzbeschreibung` VARCHAR(600) NOT NULL,
  PRIMARY KEY (`CDid`), -- no need for an extra index
  INDEX `Buchungsid_idx` (`Ausgeborgt` ASC),
  CONSTRAINT `Buchungsid`
    FOREIGN KEY (`Ausgeborgt`)
    REFERENCES `mydb`.`Buchung` (`Buchungsid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM