Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL error 1022 when creating table
    primarykey
    data
    text
    <p>MySQL Workbench came up with the following SQL to create a table:</p> <pre><code>CREATE TABLE IF NOT EXISTS `mydb`.`errors_reports` ( `error_id` INT NOT NULL , `report_short` VARCHAR(15) NOT NULL , PRIMARY KEY (`error_id`, `report_short`) , INDEX `error_id_idx` (`error_id` ASC) , INDEX `report_short_idx` (`report_short` ASC) , CONSTRAINT `error_id` FOREIGN KEY (`error_id` ) REFERENCES `mydb`.`errors` (`error_id` ) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `report_short` FOREIGN KEY (`report_short` ) REFERENCES `mydb`.`reports` (`report_short` ) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB </code></pre> <p>which looks fine to me, and there are a bunch of other very similar tables in my database which MySQL was perfectly happy to create.</p> <p>But this one...</p> <pre><code>ERROR 1022 (23000): Can't write; duplicate key in table 'errors_reports' </code></pre> <p>I can't for the life of me see any duplicate keys here. There's only one key defined!</p> <p>I'm running MySQL 5.6 with a fresh default install. There's nothing in the error log.</p> <p>Ideas?</p> <p>Edit: through a process of elimination (going back to the simplest possible definition of the table, then gradually adding bits back in) the problem appears to be this bit:</p> <pre><code>CONSTRAINT `error_id` FOREIGN KEY (`error_id` ) REFERENCES `mydb`.`errors` (`error_id` ) ON DELETE NO ACTION ON UPDATE NO ACTION, </code></pre> <p>which is particularly odd as there is identical code in several other table definitions and those are perfectly okay!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload