1

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?

  • Did you have a look in the error.log or system.log? There is usually more information provided (which classes have been called). Maybe you already created an attribute named "test"? Would be great if you could give some more information. – Anna Völkl Mar 19 '13 at 19:50
  • Hi Anna, oddly the error doesn't cause an exception.log to be created and there's nothing about this error in System.log either. I can't give any more info.. – Adam Moss Mar 20 '13 at 8:52
  • In my cases, Magento (the Magento Database) was right when an error like this one occured. Did you try to add attributes with different scopes, attribute types (text, select,...) and attribute-codes? – Anna Völkl Mar 20 '13 at 9:28
3

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.

1

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.

  • 1
    what was the extension and there did you delete to row from? thanks. – Erdem Ece May 21 '14 at 11:03
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.