Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

magento SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '363624' for key 'PRIMARY'

Tags:

mysql

magento

i have migrated a mgento installation doing the following:

  1. copied all files
  2. exported the db
  3. imported the db using mysql workbench
  4. changed the base_url's to the new domain
  5. updated local.xml to the correct settings

now im getting:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '363624' for key 'PRIMARY'

I have searched the db for this key 363624 , but it is not duplicated as the messages says

how can i solve this ?

like image 744
lior r Avatar asked Apr 07 '13 21:04

lior r


3 Answers

This helped me (clearing some of the tables):

Enter your Magento database and run following sql query:

TRUNCATE dataflow_batch_export ; 
TRUNCATE dataflow_batch_import ; 
TRUNCATE log_customer ; 
TRUNCATE log_quote ; 
TRUNCATE log_summary ; 
TRUNCATE log_summary_type ; 
TRUNCATE log_url ; 
TRUNCATE log_url_info ; 
TRUNCATE log_visitor ; 
TRUNCATE log_visitor_info ; 
TRUNCATE log_visitor_online ; 
TRUNCATE report_event ;

After that need to clear var/session dir (If your session stored in files) cause you will get same error until you clear session files.

like image 59
Oscar Avatar answered Jan 03 '23 22:01

Oscar


It is not duplicated but rather something must be trying to duplicate it.

How did you export the database? I would check that the dumped SQL file has the line "SET FOREIGN_KEY_CHECKS=0;" or similar at the top.

If not, I would drop the database and add this line to the top of the file:

SET FOREIGN_KEY_CHECKS=0;

... and this line to the bottom:

SET FOREIGN_KEY_CHECKS=1;

... then try again.

like image 43
redjam13 Avatar answered Jan 03 '23 23:01

redjam13


I was getting the same error.

For me, it turns out that the export was taking so long with the site staying 'live' that the end of the export was out of sync with the beginning.

Specifically, the 'log_visitor_info' table had about 100 more records than some of the other related visitor log tables, so the DB is trying to create a record ID from another table that already exists here.

I just deleted the last 100 or so records from this specific table and things worked again without the error. Alternatively it looks like you can mash on the f5 key until you increment past that already-existing ID and Magento will start working again.

I suspect that putting the store in maintenance mode before the export may help with this particular error.

like image 25
creuzerm Avatar answered Jan 04 '23 00:01

creuzerm