Forums / Installing on a Windows Server / DB Import Error #1062 - Duplicate entry '1' for key 1

DB Import Error #1062 - Duplicate entry '1' for key 1

Views: 9,795

Results 1 to 7 of 7
18 Oct 2011, 6:02 AM
#1
aushy avatar

aushy

New Zenner

Join Date:
Jan 2011
Posts:
5
Plugin Contributions:
0

DB Import Error #1062 - Duplicate entry '1' for key 1

Hi,
I was trying to install a new template when I accidentally installed the wrong SQL file.. basically all the products in my store were overwritten with the demo products and categories. I did do a database backup beforehand, however now I have a problem. When I go to import the database, it comes up with an error.

SQL query:

-- -- Dumping data for table address_book -- INSERT INTO address_book ..(continues to list data in the address book)

MySQL said:
#1062 - Duplicate entry '1' for key 1

How can I fix this? I really really really don't want to enter all my products again.

Edit:
v1.3.9h

18 Oct 2011, 7:31 AM
#2
aushy avatar

aushy

New Zenner

Join Date:
Jan 2011
Posts:
5
Plugin Contributions:
0

Re: DB Import Error #1062 - Duplicate entry '1' for key 1

I have a feeling I may have posted this in the wrong section.. pretty sure my site is hosted on a linux server. If a mod could move this to the appropriate section it would be great :)

18 Oct 2011, 1:30 PM
#3
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: DB Import Error #1062 - Duplicate entry '1' for key 1

aushy:

MySQL said:
#1062 - Duplicate entry '1' for key 1

How can I fix this? I really really really don't want to enter all my products again.

You'll need to DROP the table (or contents) before importing your backup.

If you use phpyadmin to create your backups, the next time you do so ensure you check the box that reads:
Add DROP TABLE statement

Cheers
Rod

ps. Don't drop the Database itself, just the tables and/or contents. I tend to drop the contents JUST IN CASE the 'create table if not exists' option hasn't been checked either.

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

18 Oct 2011, 10:48 PM
#4
aushy avatar

aushy

New Zenner

Join Date:
Jan 2011
Posts:
5
Plugin Contributions:
0

Re: DB Import Error #1062 - Duplicate entry '1' for key 1

I am pretty sure the create table if not exists box was checked, because that is the default. The only box not checked by default is the drop table.

So how I go about manually dropping the table? Or maybe just to be safe, how do I only drop the table contents?

Thanks

19 Oct 2011, 1:36 AM
#5
aushy avatar

aushy

New Zenner

Join Date:
Jan 2011
Posts:
5
Plugin Contributions:
0

Re: DB Import Error #1062 - Duplicate entry '1' for key 1

Let me use the table "address_book" as an example.

In phpmyadmin, I select my zen cart database from the drop down list on the left hand side. I then select "address_book" on the left, and also select "structure" from the top menu, upon which I am presented with a table. Under the columns heading, shows:

address_book_id
customers_id
entry_gender

Each one of these has 'drop' at the end of the line. If I drop these, is this dropping an entire table, or dropping the table contents? I think dropping the table contents is the smartest option for me to try first, as suggested above.

19 Oct 2011, 7:56 AM
#6
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: DB Import Error #1062 - Duplicate entry '1' for key 1

In phpMyAdmin, once you have selected your database then scroll to page bottom on the right.

There you will see a link for "Check All". Clicking the link will select all Tables.
To the right of that link you will see a drop-down menu showing "With selected". Choose "Drop" then press the "Go" button; bottom right.

You have now removed all previous Tables whilst still retaining your Database. You should now be able to Import your previous database.

The learning is in the doing.

Potent Products

19 Oct 2011, 10:38 AM
#7
aushy avatar

aushy

New Zenner

Join Date:
Jan 2011
Posts:
5
Plugin Contributions:
0

Re: DB Import Error #1062 - Duplicate entry '1' for key 1

Followed the instructions above and everything imported without errors.

Thanks heaps!