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

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.


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.


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.

Tags:

Mysql

Magento