Jitendra Vyas
Jitendra Vyas

Reputation: 152647

phpmyadmin error "#1062 - Duplicate entry '1' for key 1"

I dropped all tables from a database then restore(import) a backup. Afterwards I am getting error #1062 - Duplicate entry '1' for key 1.

Should i repeat the process. Or something else? Why this error is coming?

Upvotes: 3

Views: 57015

Answers (4)

Noam
Noam

Reputation: 3391

From the sounds if it, the dump has a duplicate entry inside the queries it holds.

Although this shouldn't happen, it happened to me in the past. In order to solve this, I would advise two options:

  1. Manually remove the ADD UNIQUE INDEX and/or PRIMARY KEY at the start of each table dump. Then create a same structure table, add the missing index, and INSERT IGNORE INTO new_tbl (SELECT * FROM tbl)
  2. Adding INSERT IGNORE for the insert statement in the log

Upvotes: 1

Gary Tsui
Gary Tsui

Reputation: 1755

When you export your sql from php admin

enter image description here

Select "custom" as export method"

enter image description here

then, instead of 'insert', choose "update"

This will perform update-statements and prevent duplicated inserts.

Upvotes: 7

rusly
rusly

Reputation: 1522

To fix this, when you want to export DB you can try to untick "Do not use AUTO_INCREMENT for zero values" under "Format-Specific Options:" , see image below :

enter image description here

Upvotes: -1

thomasrutter
thomasrutter

Reputation: 117333

This indicates that you have a UNIQUE or PRIMARY index on a table, and there is a duplicate value on one of the values that will be inserted into one of these indexes.

You'll need to look at which particular operation caused this error to find out which table and which row it was trying to write. Hopefully, phpMyAdmin should tell you which row of data caused the problem, shouldn't it?

One guess is that you're importing data that duplicates some data already in a table, ie you may not have removed the existing data like you thought you had. But it could be any number of things.

Upvotes: 5

Related Questions