Forums / General Questions / SQL Error : 1062 Duplicate entry '0' for key 1

SQL Error : 1062 Duplicate entry '0' for key 1

Locked

Started by wazoo on 3 May 2007, 12:36 PM · Views: 6,907

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
3 May 2007, 12:36 PM
#1
wazoo avatar

wazoo

New Zenner

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

SQL Error : 1062 Duplicate entry '0' for key 1

Hmm i just imported a db due to switching hosts for my website/forum and i have this problem when posting

 			 			 				Error in posting

[B]DEBUG MODE[/B]

SQL Error : 1062 Duplicate entry '0' for key 1

INSERT INTO phpbb_topics (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote) VALUES ('ss', 2, 1178195754, 16, 0, 0, 0)

Line : 227
File : functions_post.php

Can someone help ? thanks. :P

3 May 2007, 1:21 PM
#2
chuckl avatar

chuckl

Totally Zenned

Join Date:
Nov 2006
Location:
Papworth, Cambridgeshire, UK
Posts:
717
Plugin Contributions:
0

Re: SQL Error : 1062 Duplicate entry '0' for key 1

Usually means your database backup did not include 'auto increment' on the key fields, or that it was not part of the database create.
Requires you to edit/alter the database so those fields affected are once again auto incrementing.

3 May 2007, 1:24 PM
#3
wazoo avatar

wazoo

New Zenner

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

Re: SQL Error : 1062 Duplicate entry '0' for key 1

Hmm Which file , would would it be just funtions_posts.php? or others?

besides im not sure what i would have to do exactly in the edit to increment like u mentioned?

Help :(

3 May 2007, 1:50 PM
#4
chuckl avatar

chuckl

Totally Zenned

Join Date:
Nov 2006
Location:
Papworth, Cambridgeshire, UK
Posts:
717
Plugin Contributions:
0

Re: SQL Error : 1062 Duplicate entry '0' for key 1

Er no, your Mysql database for your Zen Cart installation is the culprit. Or, your backup of your original site on the other server is the culprit. If you look at the backup file from your original site, it is full of SQL statements such as

DROP TABLE IF EXISTS address_book;
CREATE TABLE address_book (
address_book_id int(11) NOT NULL auto_increment,

followed by a whole lot of other fields, and at the end something like

ENGINE=MyISAM AUTO_INCREMENT=24 DEFAULT CHARSET=latin1;

The above sets address_book_id as an auto incrementing field, and the last line says there are 24 entries already, so carry on from there

However, I usually SQLyog for such things, and instead, it creates

DROP TABLE IF EXISTS address_book;

CREATE TABLE address_book (
address_book_id int(11) NOT NULL,

in the backup file, omitting the auto increment.
When you attempt to add something, it fails because it is trying to use a key index of 0, which already exists.
To fix this, you have to edit the database, or edit the backup file, to add the auto increment where needed, which is just about everywhere.