0

I was doing forward engineering, I got this error as ERROR: Error 1022: Can't write; duplicate key in table 'emails', I tried to change name constraints but same error was getting, Can you help me to solve this error thanks

Executing SQL script in server
ERROR: Error 1022: Can't write; duplicate key in table 'emails'
SQL Code:
        -- -----------------------------------------------------
        -- Table `mydb`.`Emails`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `mydb`.`Emails` (
          `EId` INT NOT NULL,
          `Type` VARCHAR(45) NULL,
          `Email` VARCHAR(45) NULL,
          INDEX `ProfileId_idx` (`EId` ASC),
          CONSTRAINT `ProfileId`
            FOREIGN KEY (`EId`)
            REFERENCES `mydb`.`personprofile` (`ProfileId`)
            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
Utsav
  • 7,914
  • 2
  • 17
  • 38
Vinit Mapari
  • 439
  • 3
  • 7
  • 15
  • 1
    Check again if `profileid` constraint exists in database by using the answer in this [question](https://stackoverflow.com/questions/18056786/error-1022-cant-write-duplicate-key-in-table) – Utsav Jun 10 '18 at 05:10
  • CREATE TABLE IF NOT EXISTS `mydb`.`personprofile` ( `ProfileId` INT NOT NULL, `FirstName` VARCHAR(45) NULL, `LastName` VARCHAR(45) NULL, `Birthdate` VARCHAR(45) NULL, `MartialStatus` VARCHAR(45) NULL, `Gender` VARCHAR(45) NULL, `Height` INT NULL, `ValidIdTypes` VARCHAR(45) NULL,...... ` yes exists – Vinit Mapari Jun 10 '18 at 05:16
  • So that is the problem right! Try changing the constraint names. – Utsav Jun 10 '18 at 06:08
  • I've also had this problem with MySQL 5.7.26, but being sure I didn't have any other existing key with the same name. There had previously been a key with the same name, but it had been deleted. I solved it by exporting the schema, deleting it and importing it again. I imagine it will be some MySQL problem that does not empty its caches well, despite having restarted the service even, or something similar. – Aníbal May 09 '19 at 12:06

0 Answers0