Zen Cart Logo
Forums / General Questions / 1062 Duplicate entry '0' for key 1 after export/import of database

1062 Duplicate entry '0' for key 1 after export/import of database

Locked

Views: 62,223

Results 1 to 20 of 38
This thread is locked. New replies are disabled.
16 May 2006, 10:37 AM
#1
glovario avatar

glovario

New Zenner

Join Date:
Apr 2005
Location:
Derby, UK
Posts:
7
Plugin Contributions:
0

1062 Duplicate entry '0' for key 1 after export/import of database

Can someone please help I am having some major problems I changed servers a few days ago at first I got this error in the admin section I found a fix on the forum and it worked.

A couple of days ago this error started to happen on the front page all content disappears and just underneath the side boxes on the left and the side boxes on the right completely disappear.

If I upload the old database from the backup I made before I moved servers it is fine at first but then the day after this problem is back again.

I really need some help on this I have to get this sit backup and running I would appreciate any help that can be given.

16 May 2006, 11:08 AM
#2
glovario avatar

glovario

New Zenner

Join Date:
Apr 2005
Location:
Derby, UK
Posts:
7
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

I have managed to resolve this now from what I can gather the problem was coming from anything to do with history stored in the MySql database.

If anyone else gets this problem drop everything from the following tables:

  • admin_activity_log
  • banners_history
  • counter_history
  • sessions

This should sort your problem out.

18 May 2006, 2:20 PM
#3
targetsp avatar

targetsp

New Zenner

Join Date:
May 2006
Posts:
2
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

Hello i to have this problem i am using secpay for payment the first order i ever tested on the site worked then the second one didnt giving me a '1062 Duplicate entry '0' for key 1' on a blank page, so i deleted my first order in admin and the next order worked but the same fault again with the second test, it looks like the orders are not counting up please can some one point me in the right direction thank you.:smile:

19 May 2006, 11:06 AM
#4
glovario avatar

glovario

New Zenner

Join Date:
Apr 2005
Location:
Derby, UK
Posts:
7
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

this problem has come back again please help.

20 May 2006, 7:34 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

What's your URL?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

22 May 2006, 1:34 PM
#6
adanker avatar

adanker

New Zenner

Join Date:
May 2005
Posts:
2
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

I am having a similar problem. I can tell you that I have moved my entire site recently from a Shared Hosting server to another shared server. The only difference between the two MySQL setup's is version numbers. I exported from the old to the new and everything took until I ran the program. I get this :
http://savannahspasecrets.com (see all the way bottom left column).

If I remove the most recent row written the app does fine until the next row... which of course is already there. It's like the app has reset the count or lost what the last ID it was on?

The app, whether logged in as admin or visitor, writes starting from '0' to each table??

22 May 2006, 5:43 PM
#7
glovario avatar

glovario

New Zenner

Join Date:
Apr 2005
Location:
Derby, UK
Posts:
7
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

Please someone must no what is causing this and how to fix it any help will be much appreciated

22 May 2006, 7:17 PM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

There are approx 100 tables in a Zen Cart database. Thus, the cause of that error could be related to any one of them.

I tried to help earlier by asking:> DrByte:

What's your URL?... but you never replied.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

22 May 2006, 7:17 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

adanker:

I get this :
http://savannahspasecrets.com (see all the way bottom left column).

I don't see any errors on that page.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

1 Jun 2006, 6:28 AM
#10
vixay avatar

vixay

New Zenner

Join Date:
Apr 2006
Posts:
17
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

1062 Duplicate entry '0' for key 1
in:
[insert into admin_activity_log (access_date, admin_id, page_accessed, page_parameters, ip_address) values (now(), '1', 'attributes_controller.php', '', '**.**.0.64')]
If you were entering information, press the BACK button in your browser and re-check the information you had entered to be sure you left no blank fields.

Thats the error i get.

I assume this is because the Now() function is returning 0 and not the correct date & time...
Any suggestions on how to fix it?

Btw, this happens only when using the admin interface...
i'll try using the fix_cache_key, maybe that is the problem...
have to wait to ftp it up though.

Just tried fix_cache_key... doesn't help solve problem.

--
"Drunk on the Nectar of Life" - me

1 Jun 2006, 6:41 AM
#11
vixay avatar

vixay

New Zenner

Join Date:
Apr 2006
Posts:
17
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

** SOLUTION: **
Exectute the following SQL code in PHPMyAdmin... (Copy & paste)
This will change the log_id column to auto_increment... you get this error when it doesn't auto_increment!

ALTER TABLE admin_activity_log CHANGE COLUMN log_id log_id int(15) NOT NULL auto_increment;

Found in thread http://www.zen-cart.com/forum/showpost.php?p=174525&postcount=13

Worked for me!

Hope it helps everyone else out there...

--
"Drunk on the Nectar of Life" - me

1 Jun 2006, 12:24 PM
#12
adanker avatar

adanker

New Zenner

Join Date:
May 2005
Posts:
2
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

As you can probably tell my issue with savannahspasecrets.com has been resolved. For the duplicate entry error message that I received I simply compared the original sql file that built the original tables for the database to the errored database. I found that for every "key" ID I was missing the auto-increment setting. In this case upon every new data entry to what ever table it was trying to start from "0" and then the following new row written would try to write over this same row key value with "0"... kicking back to the script a <b>1062 Duplicate entry '0' for key 1</b> error! Bingo, this solution has been working for my zen-cart for 2 weeks now.

Good luck, I will try to help anyone else if their situation is a bit different.

Aaron

3 Jun 2006, 4:44 AM
#13
vixay avatar

vixay

New Zenner

Join Date:
Apr 2006
Posts:
17
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

adanker:

As you can probably tell my issue with savannahspasecrets.com has been resolved. For the duplicate entry error message that I received I simply compared the original sql file that built the original tables for the database to the errored database. I found that for every "key" ID I was missing the auto-increment setting. In this case upon every new data entry to what ever table it was trying to start from "0" and then the following new row written would try to write over this same row key value with "0"... kicking back to the script a <b>1062 Duplicate entry '0' for key 1</b> error! Bingo, this solution has been working for my zen-cart for 2 weeks now.

Good luck, I will try to help anyone else if their situation is a bit different.

Aaron

would be cool if someone posted an SQL patch to fix alll auto_increment collumns that are not auto_increment now...
or is there a better way to do it, without screwing up your migrated data?

I fixed the one in the admin activity log, but i have to fix it in the other tables too... the banner history log i guess... (when the error shows up on the bottom of the page on the main site)

ALTER TABLE admin_activity_log CHANGE COLUMN log_id log_id int(15) NOT NULL auto_increment;
ALTER TABLE banners_history CHANGE COLUMN banners_history_id banners_history_id int(11) NOT NULL auto_increment;

probably need to edit other tables with history in it...
e.g. orders_status_history, paypal_payment_status_history, project_version_history

--
"Drunk on the Nectar of Life" - me

4 Jun 2006, 5:02 AM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

If the tables which are "supposed to have" auto-increment on them ... do not... then you've done something odd with your database. When Zen Cart installs them, they are already set to auto-increment.

My point is that there's not so much a need for a script to set them to auto-increment, but rather the more important key is to find out WHY they have lost the auto-increment setting in the first place....

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

4 Jun 2006, 9:09 PM
#15
miss60 avatar

miss60

New Zenner

Join Date:
May 2006
Posts:
1
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

I've just moved my site by doing a database export & import and ran into the same problem. i think I may have resolved it by reinstating the autoincrement in the Extra column of log_id in the admin_activity_log table.

6 Jun 2006, 7:06 AM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

I suppose one potential cause of losing auto-increment settings is if you do a backup via phpMyAdmin and uncheck the box related to retaining auto-increment values.
Technically this shouldn't leave the auto-increment out of the structure/schema, just not include the current value in it.
Perhaps something's busted there...

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

12 Jun 2006, 9:07 AM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

Okay, having found more cases of problems identical to this, it appears that the cause is related to the way in which various hosts will export backups of data to transfer from one server to another. I'm guessing that many of them don't include the auto-increment property by default ... which is very unfortunate. I'm rather surprised to have not seen this reported earlier. Nevertheless, here's a script to reinstate auto-increment properties on tables in v1.3.x:```

This script simply rebuilds the auto-increment settings on tables which should have them.

ALTER TABLE upgrade_exceptions CHANGE COLUMN upgrade_exception_id upgrade_exception_id smallint(5) NOT NULL auto_increment;
ALTER TABLE address_book CHANGE COLUMN address_book_id address_book_id int(11) NOT NULL auto_increment;
ALTER TABLE address_format CHANGE COLUMN address_format_id address_format_id int(11) NOT NULL auto_increment;
ALTER TABLE admin CHANGE COLUMN admin_id admin_id int(11) NOT NULL auto_increment;
ALTER TABLE admin_activity_log CHANGE COLUMN log_id log_id int(15) NOT NULL auto_increment;
ALTER TABLE authorizenet CHANGE COLUMN id id int(11) unsigned NOT NULL auto_increment;
ALTER TABLE banners CHANGE COLUMN banners_id banners_id int(11) NOT NULL auto_increment;
ALTER TABLE banners_history CHANGE COLUMN banners_history_id banners_history_id int(11) NOT NULL auto_increment;
ALTER TABLE categories CHANGE COLUMN categories_id categories_id int(11) NOT NULL auto_increment;
ALTER TABLE configuration CHANGE COLUMN configuration_id configuration_id int(11) NOT NULL auto_increment;
ALTER TABLE configuration_group CHANGE COLUMN configuration_group_id configuration_group_id int(11) NOT NULL auto_increment;
ALTER TABLE countries CHANGE COLUMN countries_id countries_id int(11) NOT NULL auto_increment;
ALTER TABLE coupon_email_track CHANGE COLUMN unique_id unique_id int(11) NOT NULL auto_increment;
ALTER TABLE coupon_gv_queue CHANGE COLUMN unique_id unique_id int(5) NOT NULL auto_increment;
ALTER TABLE coupon_redeem_track CHANGE COLUMN unique_id unique_id int(11) NOT NULL auto_increment;
ALTER TABLE coupon_restrict CHANGE COLUMN restrict_id restrict_id int(11) NOT NULL auto_increment;
ALTER TABLE coupons CHANGE COLUMN coupon_id coupon_id int(11) NOT NULL auto_increment;
ALTER TABLE currencies CHANGE COLUMN currencies_id currencies_id int(11) NOT NULL auto_increment;
ALTER TABLE customers CHANGE COLUMN customers_id customers_id int(11) NOT NULL auto_increment;
ALTER TABLE customers_basket CHANGE COLUMN customers_basket_id customers_basket_id int(11) NOT NULL auto_increment;
ALTER TABLE customers_basket_attributes CHANGE COLUMN customers_basket_attributes_id customers_basket_attributes_id int(11) NOT NULL auto_increment;
ALTER TABLE email_archive CHANGE COLUMN archive_id archive_id int(11) NOT NULL auto_increment;
ALTER TABLE featured CHANGE COLUMN featured_id featured_id int(11) NOT NULL auto_increment;
ALTER TABLE files_uploaded CHANGE COLUMN files_uploaded_id files_uploaded_id int(11) NOT NULL auto_increment;
ALTER TABLE geo_zones CHANGE COLUMN geo_zone_id geo_zone_id int(11) NOT NULL auto_increment;
ALTER TABLE group_pricing CHANGE COLUMN group_id group_id int(11) NOT NULL auto_increment;
ALTER TABLE ezpages CHANGE COLUMN pages_id pages_id int(11) NOT NULL auto_increment;
ALTER TABLE languages CHANGE COLUMN languages_id languages_id int(11) NOT NULL auto_increment;
ALTER TABLE layout_boxes CHANGE COLUMN layout_id layout_id int(11) NOT NULL auto_increment;
ALTER TABLE manufacturers CHANGE COLUMN manufacturers_id manufacturers_id int(11) NOT NULL auto_increment;
ALTER TABLE media_clips CHANGE COLUMN clip_id clip_id int(11) NOT NULL auto_increment;
ALTER TABLE media_manager CHANGE COLUMN media_id media_id int(11) NOT NULL auto_increment;
ALTER TABLE media_types CHANGE COLUMN type_id type_id int(11) NOT NULL auto_increment;
ALTER TABLE meta_tags_categories_description CHANGE COLUMN categories_id categories_id int(11) NOT NULL auto_increment;
ALTER TABLE meta_tags_products_description CHANGE COLUMN products_id products_id int(11) NOT NULL auto_increment;
ALTER TABLE music_genre CHANGE COLUMN music_genre_id music_genre_id int(11) NOT NULL auto_increment;
ALTER TABLE newsletters CHANGE COLUMN newsletters_id newsletters_id int(11) NOT NULL auto_increment;
ALTER TABLE orders CHANGE COLUMN orders_id orders_id int(11) NOT NULL auto_increment;
ALTER TABLE orders_products CHANGE COLUMN orders_products_id orders_products_id int(11) NOT NULL auto_increment;
ALTER TABLE orders_products_attributes CHANGE COLUMN orders_products_attributes_id orders_products_attributes_id int(11) NOT NULL auto_increment;
ALTER TABLE orders_products_download CHANGE COLUMN orders_products_download_id orders_products_download_id int(11) NOT NULL auto_increment;
ALTER TABLE orders_status_history CHANGE COLUMN orders_status_history_id orders_status_history_id int(11) NOT NULL auto_increment;
ALTER TABLE orders_total CHANGE COLUMN orders_total_id orders_total_id int(10) unsigned NOT NULL auto_increment;
ALTER TABLE paypal_session CHANGE COLUMN unique_id unique_id int(11) NOT NULL auto_increment;
ALTER TABLE paypal CHANGE COLUMN paypal_ipn_id paypal_ipn_id int(11) unsigned NOT NULL auto_increment;
ALTER TABLE paypal_testing CHANGE COLUMN paypal_ipn_id paypal_ipn_id int(11) unsigned NOT NULL auto_increment;
ALTER TABLE paypal_payment_status CHANGE COLUMN payment_status_id payment_status_id int(11) NOT NULL auto_increment;
ALTER TABLE paypal_payment_status_history CHANGE COLUMN payment_status_history_id payment_status_history_id int(11) NOT NULL auto_increment;
ALTER TABLE product_type_layout CHANGE COLUMN configuration_id configuration_id int(11) NOT NULL auto_increment;
ALTER TABLE product_types CHANGE COLUMN type_id type_id int(11) NOT NULL auto_increment;
ALTER TABLE products CHANGE COLUMN products_id products_id int(11) NOT NULL auto_increment;
ALTER TABLE products_attributes CHANGE COLUMN products_attributes_id products_attributes_id int(11) NOT NULL auto_increment;
ALTER TABLE products_description CHANGE COLUMN products_id products_id int(11) NOT NULL auto_increment;
ALTER TABLE products_options_values_to_products_options CHANGE COLUMN products_options_values_to_products_options_id products_options_values_to_products_options_id int(11) NOT NULL auto_increment;
ALTER TABLE project_version CHANGE COLUMN project_version_id project_version_id tinyint(3) NOT NULL auto_increment;
ALTER TABLE project_version_history CHANGE COLUMN project_version_id project_version_id tinyint(3) NOT NULL auto_increment;
ALTER TABLE query_builder CHANGE COLUMN query_id query_id int(11) NOT NULL auto_increment;
ALTER TABLE record_artists CHANGE COLUMN artists_id artists_id int(11) NOT NULL auto_increment;
ALTER TABLE record_company CHANGE COLUMN record_company_id record_company_id int(11) NOT NULL auto_increment;
ALTER TABLE reviews CHANGE COLUMN reviews_id reviews_id int(11) NOT NULL auto_increment;
ALTER TABLE salemaker_sales CHANGE COLUMN sale_id sale_id int(11) NOT NULL auto_increment;
ALTER TABLE specials CHANGE COLUMN specials_id specials_id int(11) NOT NULL auto_increment;
ALTER TABLE tax_class CHANGE COLUMN tax_class_id tax_class_id int(11) NOT NULL auto_increment;
ALTER TABLE tax_rates CHANGE COLUMN tax_rates_id tax_rates_id int(11) NOT NULL auto_increment;
ALTER TABLE template_select CHANGE COLUMN template_id template_id int(11) NOT NULL auto_increment;
ALTER TABLE zones CHANGE COLUMN zone_id zone_id int(11) NOT NULL auto_increment;
ALTER TABLE zones_to_geo_zones CHANGE COLUMN association_id association_id int(11) NOT NULL auto_increment;



**NOTE: The up-to-date version of this script is ALSO available in the Zen Cart master fileset ... look for:  /zc_install/sql/db_rebuild_autoincrement.sql**

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

20 Jun 2006, 5:42 AM
#18
vixay avatar

vixay

New Zenner

Join Date:
Apr 2006
Posts:
17
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

Thanks a lot for this Dr. Byte. I think you are correct in that the export import doesn't work out correctly.
Can a moderator merge all the topics that have the same symptom? as that will surely get people to the answer faster...
Maybe this should be added to the FAQ?

--
"Drunk on the Nectar of Life" - me

28 Jun 2006, 3:04 AM
#19
cshart avatar

cshart

Zen Follower

Join Date:
Mar 2005
Posts:
370
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

I am experiencing this problem in my admin area when I try to go anywhere.

What can be done to correct this?

cshart

28 Jun 2006, 6:35 PM
#20
mark_kimsal avatar

mark_kimsal

New Zenner

Join Date:
Jun 2006
Posts:
14
Plugin Contributions:
0

Re: 1062 Duplicate entry '0' for key 1 after export/import of database

When exporting from mysql4.1 and using the --compat=mysql40 or --compaty-mysql3 flags, mysqldump export command will not give you proper auto-increment flags. This is considered proper behavior by MySQL AB and will not be changed. When going from 4.1 to 4.0 or 3.23 the most common issue is the syntax at the end of the table definition: ENGINE= and DEFAULT_CHARSET=.

Here is a general fix for dumping from 4.1 -> 4.0 or 3.23 when not using the --compat flag. This only fixes the most general problem with the table definitions, I don't think it works on enums, and it is only safe to use on a file that has only table definitions, not table definitions and data.

sed -e 's/\ ENGINE=([a-zA-Z])\ DEFAULT\ CHARSET=[a-zA-Z0-9]/\ TYPE=\1/' foobar.mysql > foobar.fixed.mysql

or, for a directory of files

for x in ls mydumpdir/*.sql
do
sed -e 's/\ ENGINE=([a-zA-Z])\ DEFAULT\ CHARSET=[a-zA-Z0-9]/\ TYPE=\1/' $x > fixed.$x
done