#1062 – Duplicate entry ‘1’ for key ‘PRIMARY’

I am at a complete loss here. I have two databases. One on my localhost site that I use for development and one on my remote site that I use for my live (production) site. I manage both of them through phpMyadmin. As I have been doing for months now, when I need to update the live site, I dump the related database and import the database from my localhost site.

Now, no matter what I try, I keep getting this error:

SQL query:

-- Dumping data for table `oc_address_type`
INSERT INTO  `oc_address_type` (  `address_type_id` ,  `address_type_name` ) 
VALUES ( 1,  'Billing' ) , ( 2,  'Shipping' ) ;

MySQL said: Documentation

#1062 – Duplicate entry ‘1’ for key ‘PRIMARY’

I tried creating a new blank database on my localhost and importing into that but same results. I have validated all of the tables and indexes and cannot find anything wrong there.

Any suggestions please as I am completely down until this gets resolved.

By the way, I am completely dropping all tables and importing structure and data. This has always worked until today.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

you need to dump with the drop statements. The table exists and has data already and your trying to insert more which is identical. Im not 100% sure on phpmyadmin but the dumps will have an option for “add drop table” statements

Method 2

Dump your database on localhost with “mysqldump –insert-ignore …” then try to import with phpmyadmin on your live machine.

Or try to connect to your live database with command line tools (configure your database to be able to connect from other hosts than “localhost” first!)

Then you can try following:

$ mysql -f -p < yourdump.sql

with -f “force” you can ignore errors during importing. It’s the same as adding “–force” parameter to “mysqlimport”.

Method 3

The problem is related with your file – you are trying to create a DB using a copy – at the top of your file you will find something like this:


and I’m sure that you already have a DB with this name – IN THE SAME SERVER – please check, because you are trying to overwrite!! Just change the name OR (better) ERASE THIS LINE!

Method 4

For me the foreign_key_checks and truncate table options was useful.

SET foreign_key_checks = 0;
TRUNCATE `oc_address_type`;
SET foreign_key_checks = 1;

Run the above sql script, and after the import.

Method 5

I had this same issue, my problem was I had a primary key column called unique_id and when you try to add two of the same value in that primary keyed column, it comes back with the error below.

#1062 - Duplicate entry '1' for key 'PRIMARY'
enter image description here

A primary key column’s data is all suppose to be different, so that bottom 1 I changed to 3 and the error went away.

Your MySql is not corrupt, like previous answers and comments.

Method 6

you need to delete any previous tables that you are over-writing. if you are doing a complete restore of all tables, delete all existing tables.

Method 7

I have met the same problem, I drop the table and rebuilt the database, then the problem solved.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x