Magento: Integrity constraint violation: 1062 Duplicate entry '100002112' for key 2

Magento: Integrity constraint violation: 1062 Duplicate entry '100002112' for key 2

August 9, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Integrity constraint violation: 1062 Duplicate entry '100002112' for key 2

Title: Resolving Magento Integrity Constraint Violations After an Upgrade

As a senior developer who has worked extensively with Magento, I understand your frustration when encountering errors after an upgrade. The “Integrity constraint violation” message you’re seeing is quite common but can be tricky to resolve for those new to the platform.

Understanding the Error

The error message 1062 Duplicate entry '100002112' for key 2 suggests that there are duplicate entries in one of your Magento tables, specifically violating a unique constraint on column 100002112. This often occurs when data is incorrectly migrated during the upgrade process.

Initial Troubleshooting Steps

You’ve taken some essential initial steps:

  • Truncating log tables: Clearing the log tables can help reduce the size of the database and sometimes resolves temporary conflicts.
  • Checking for duplicate SKUs: Ensuring product identifiers are unique prevents many common issues in Magento.
  • Attempting reindexing: Reindexing is a critical part of keeping your store’s data consistent, but it seems to have failed this time around.

Deep Diving into the Issue

Let’s explore some targeted solutions:

Identifying the Affected Table

The key 2 refers to an index in one of your Magento tables. To find out which table is causing the issue:

  1. Open your MySQL database.
  2. Run the following command: SHOW INDEX FROM catalog_product_entity WHERE Key_name='PRIMARY';
  3. The result should show you that the primary key column is entity_id.

Investigating Duplicate Entries

Since your primary key (entity_id) seems to be the culprit, let’s check if there are any duplicate entries:

SELECT entity_id, sku FROM catalog_product_entity WHERE entity_id = 100002112;

If you see multiple rows returned, this confirms that there are indeed duplicate entity_id values for a single SKU.

Resolving the Issue

Option A: Clean up Duplicates Manually

For small datasets:

  • Identify duplicate entries.
  • Delete the excess rows using SQL commands like DELETE FROM catalog_product_entity WHERE entity_id = 100002112 LIMIT 1;
  • Reindex your product flat data and update prices.

For larger stores, I recommend using a script to clean up duplicates systematically. You can find an example of such a script on the Laravel Company blog. This script ensures that your data remains consistent and doesn’t introduce new errors.

Option C: Contact Magento Support

If you’re still unable to resolve the issue, it’s wise to reach out to official Magento support or contact a professional Magento developer. They can provide guidance tailored to your specific setup.

Conclusion

Resolving integrity constraint violations in Magento often requires a combination of data cleanup and reindexing. It’s essential to approach these issues systematically, checking for duplicates before attempting repairs.

I recommend using the script mentioned earlier if you’re dealing with a large dataset. This ensures a comprehensive clean-up without introducing new errors.

Remember, keeping your Magento version up-to-date is crucial for security and compatibility, but it’s equally important to follow the official upgrade instructions diligently.

If you ever need professional assistance or want to learn more about Magento development best practices, don’t hesitate to reach out to us at Laravel Company. We’re always here to help!

Catalog Indexing Database Deployment

Our network