1

I am not an expert on databases but I'm modeling a database on mysqlworkbench 8.0.13 and when I try to run the script it breaks at this table(regimes). I can't figure out what KEY 'NAME' it is referring to. There's no key called name on this table.

I use this table's id as FK on two other tables. And both relationships are ONE-TO-MANY. But I don't think this should be a problem. Can anyone please be so kind as to point me in the right direction to solve this problem?

ERROR LOG:

Executing SQL script in server
ERROR: Error 1062: Duplicate entry 'mydb/regimes' for key 'name'
SQL Code:
        CREATE TABLE IF NOT EXISTS `mydb`.`regimes` (
          `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
          `description` VARCHAR(255) NOT NULL,
          `created_at` TIMESTAMP NULL DEFAULT NULL,
          `updated_at` TIMESTAMP NULL DEFAULT NULL,
          `deleted_at` TIMESTAMP NULL DEFAULT NULL,
          PRIMARY KEY (`id`))
        ENGINE = InnoDB
        DEFAULT CHARACTER SET = utf8mb4
        COLLATE = utf8mb4_unicode_ci

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

Fetching back view definitions in final form.
Nothing to fetch

COMPANIES TABLE

CREATE TABLE IF NOT EXISTS `mydb`.`vacancies` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `company_id` INT UNSIGNED NOT NULL,
  `manager_id` INT UNSIGNED NOT NULL,
  `regime_id` INT UNSIGNED NOT NULL,
  `vacancy_status_id` INT UNSIGNED NOT NULL,
  `vacancy_type_id` INT UNSIGNED NOT NULL,
  `title` VARCHAR(255) NOT NULL,
  `area` VARCHAR(255) NOT NULL,
  `description` TEXT NULL DEFAULT NULL,
  `exam_filename` VARCHAR(255) NULL DEFAULT NULL,
  `workload` VARCHAR(255) NOT NULL,
  `remuneration` VARCHAR(255) NOT NULL,
  `quantity` INT NOT NULL,
  `city` VARCHAR(255) NOT NULL,
  `soft_skills` VARCHAR(500) NOT NULL,
  `level` VARCHAR(255) NOT NULL,
  `specialty` VARCHAR(255) NOT NULL,
  `skills` VARCHAR(2000) NULL DEFAULT NULL,
  `help` TINYINT(1) NOT NULL,
  `created_at` TIMESTAMP NULL DEFAULT NULL,
  `updated_at` TIMESTAMP NULL DEFAULT NULL,
  `deleted_at` TIMESTAMP NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_vacancies_companies1_idx` (`company_id` ASC) VISIBLE,
  INDEX `fk_vacancies_managers1_idx` (`manager_id` ASC) VISIBLE,
  INDEX `fk_vacancies_vacancy_types1_idx` (`vacancy_type_id` ASC) VISIBLE,
  INDEX `fk_vacancies_vacancy_statuses1_idx` (`vacancy_status_id` ASC) VISIBLE,
  INDEX `fk_vacancies_regimes1_idx` (`regime_id` ASC) VISIBLE,
  CONSTRAINT `fk_vacancies_companies1`
    FOREIGN KEY (`company_id`)
    REFERENCES `mydb`.`companies` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_vacancies_managers1`
    FOREIGN KEY (`manager_id`)
    REFERENCES `mydb`.`managers` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_vacancies_vacancy_types1`
    FOREIGN KEY (`vacancy_type_id`)
    REFERENCES `mydb`.`vacancy_types` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_vacancies_vacancy_statuses1`
    FOREIGN KEY (`vacancy_status_id`)
    REFERENCES `mydb`.`vacancy_statuses` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_vacancies_regimes1`
    FOREIGN KEY (`regime_id`)
    REFERENCES `mydb`.`regimes` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB

PROFESSIONAL_PROFILES

CREATE TABLE IF NOT EXISTS `mydb`.`professional_profiles` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `talent_id` INT UNSIGNED NOT NULL,
  `regime_id` INT UNSIGNED NOT NULL,
  `vacancy_type_id` INT UNSIGNED NOT NULL,
  `specialty` VARCHAR(255) NOT NULL,
  `level` VARCHAR(255) NOT NULL,
  `available` TINYINT(1) NOT NULL,
  `curriculum_filename` VARCHAR(255) NOT NULL,
  `soft_skills` VARCHAR(500) NOT NULL,
  `relocation` TINYINT(1) NOT NULL,
  `current_company` VARCHAR(255) NULL DEFAULT NULL,
  `current_remuneration` VARCHAR(255) NULL DEFAULT NULL,
  `intended_remuneration` VARCHAR(255) NULL DEFAULT NULL,
  `remote` TINYINT(1) NOT NULL,
  `meeting_start` TIME NOT NULL,
  `meeting_end` TIME NOT NULL,
  `created_at` TIMESTAMP NULL DEFAULT NULL,
  `updated_at` TIMESTAMP NULL DEFAULT NULL,
  `deleted_at` TIMESTAMP NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_professional_profiles_talents1_idx` (`talent_id` ASC) VISIBLE,
  INDEX `fk_professional_profiles_vacancy_types1_idx` (`vacancy_type_id` ASC) VISIBLE,
  INDEX `fk_professional_profiles_regimes1_idx` (`regime_id` ASC) VISIBLE,
  CONSTRAINT `fk_professional_profiles_talents1`
    FOREIGN KEY (`talent_id`)
    REFERENCES `mydb`.`talents` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_professional_profiles_vacancy_types1`
    FOREIGN KEY (`vacancy_type_id`)
    REFERENCES `mydb`.`vacancy_types` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_professional_profiles_regimes1`
    FOREIGN KEY (`regime_id`)
    REFERENCES `mydb`.`regimes` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB

1 Answer 1

1

Error 1062: Duplicate entry ... is an error indicating you've tried to INSERT or UPDATE (explicitly or implicitly) a row in a table using a key that already exists and that key column is defined as being unique in the table/index. This could be a primary key or another key that has been explicitly defined as unique. However, in your case, I suspect the duplicate entry results from trying to create an index with the same name twice. (I came to that conclusion because the index definitions themselves are also stored in a table, and the error you get refers to the name of your table as a value for the duplicate key.)

That said, I don't think the CREATE TABLE statement for regimes is what is causing this error. Your error log says you successfully ran 49 statements, and 1 statement resulted in an error. In your script, look for statements that create the name key. Do you have any CREATE UNIQUE INDEX name ON regimes ... or ALTER TABLE regimes statements? That would be something to look out for.

1
  • I solved it before reading your answer. But I guess I might have had a unique index or alter table as you pointed out. I used the auto generated script. I had to remove the table and run the script then add the table again and make the relationships and before run an alter table and everything went fine. Commented Dec 2, 2018 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.