Error When Adding Attribute: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 1

magento.stackexchange https://magento.stackexchange.com/questions/1440

Question

I am trying to add a new attribute, but seem to have a problem with what I think is the increment IDs of the primary key of the table eav_attribute, which is attribute_id.

Every time I try to add a new attribute I get this error:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 1

enter image description here

I have tried re-indexing, clearing the cache and have truncated all log tables to no effect. A category attribute has been successfully added in a MySQL setup file which I think may have caused the auto increment to come out of sync?

Has anybody experienced this error before?

Was it helpful?

Solution 2

The issue was that we had an extension installed which created a product attribute and somehow it got inserted with ID 0. This basically screwed the Auto Increment and meant that the next time we tried to create an attribute it used ID 1.

We deleted the row and uninstalled the extension then it worked fine.

OTHER TIPS

I have seen this problem before. It has occurred when the database was being written to outside of the Magento API and something went wrong. An easy solution is to turn on the MySQL general log to record all sql queries. On the command line be looking at the mysql general log in realtime by using the tail program and the -f flag, like tail -f general.log

Now try to perform the action that's giving you the integrity constraint violation, you should see the attempted sql query in the log. With this info you should be able to better trace the problem and if needed, delete a bad entry in the database.

In my case the extension table was "amasty_amconf_attribute" , I deleted the row which has 0 for the "attribute_id" column . Hope this will help someone in future.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top