PDA

View Full Version : 1062 Duplicate entry '31' for key 'PRIMARY'


topvip
2012-04-08, 08:02 AM
Problem:

1062 Duplicate entry '31' for key 'PRIMARY'
in:
[insert into customers_info (customers_info_id, customers_info_number_of_logons, customers_info_date_account_created) values ('31', '0', now())]


You have probably done some sort of database backup/restore which has lost some settings or corrupted data.

The fastest (although not really the most recommended) way to fix it is to rebuild the table with the right structure.
The following will LOSE ALL YOUR CUSTOMER BASKET DATA, but should get rid of the error.
You can do this via the Admin->Tools->Install SQL Patch option, or via phpMyAdmin:

DROP TABLE IF EXISTS customers_basket;
CREATE TABLE customers_basket (
customers_basket_id int(11) NOT NULL auto_increment,
customers_id int(11) NOT NULL default '0',
products_id tinytext NOT NULL,
customers_basket_quantity float NOT NULL default '0',
final_price decimal(15,4) NOT NULL default '0.0000',
customers_basket_date_added varchar(8) default NULL,
PRIMARY KEY (customers_basket_id),
KEY idx_customers_id_zen (customers_id)
) TYPE=MyISAM;

DROP TABLE IF EXISTS customers_basket_attributes;
CREATE TABLE customers_basket_attributes (
customers_basket_attributes_id int(11) NOT NULL auto_increment,
customers_id int(11) NOT NULL default '0',
products_id tinytext NOT NULL,
products_options_id varchar(64) NOT NULL default '0',
products_options_value_id int(11) NOT NULL default '0',
products_options_value_text BLOB NULL,
products_options_sort_order text NOT NULL,
PRIMARY KEY (customers_basket_attributes_id),
KEY idx_cust_id_prod_id_zen (customers_id,products_id(36))
) TYPE=MyISAM;