Duplicate entry for key Print

  • plugins, database, restore, woocommerce, errors, troubleshooting, guide, howto
  • 0

An insert violated a uniqueness constraint.

WHAT IT MEANS

The code tried to insert a row with a value that must be unique and already exists.

COMMON CONTEXTS

Importing data that already exists A plugin attempting to create something it already created Two processes inserting simultaneously An interrupted operation being retried

DURING AN IMPORT

Importing over existing data. Drop the tables first, then import cleanly.

Importing a full dump into a database that already has content produces this on nearly every row.

DURING NORMAL OPERATION

A plugin conflict, or an operation retried after a partial failure.

Check whether the operation partly succeeded before failing.

THE AUTO-INCREMENT CASE

If the error mentions PRIMARY and an ID, the table's auto-increment counter may be out of step with the data, usually after a partial restore.

Repairing or rebuilding the table resolves it.

WHAT TO DO

Establish whether the data genuinely already exists. If so, the insert should not be happening and the code or the process is wrong.

If it does not, the constraint or the counter is the problem.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot