Reputation: 152647
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
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:
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)
INSERT IGNORE
for the insert statement in the logUpvotes: 1
Reputation: 1755
When you export your sql from php admin
Select "custom" as export method"
then, instead of 'insert', choose "update"
This will perform update-statements and prevent duplicated inserts.
Upvotes: 7
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 :
Upvotes: -1
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