How to Fix Magento Upgrade Error: SQLSTATE[23000]: Integrity constraint violation

This error is very common when upgrading Magento. We recently came across it when upgrading a client from to but it can happy for any version. The error typically looks like the following:

SQLSTATE[23000]: Integrity constraint violation:

To fix it, first try clearing your cache and try loading your site so the upgrade process can restart. If that doesn’t work, you need to update the initStatements in app/etc/config.xml. Change:

[sourcecode language=”xml”]
<initStatements>SET NAMES utf8</initStatements>


[sourcecode language=”xml”]<initStatements>SET NAMES utf8; SET FOREIGN_KEY_CHECKS=0; SET UNIQUE_CHECKS=0;</initStatements>[/sourcecode]

That should do the trick. Make sure you change it back once the upgrade is done. If you’re still having problems, check out our tips for upgrading Magento. If that doesn’t help you, leave a comment and we’ll try to point you in the right direction