I have mistakenly deleted custom product attribute. Now This attribute has been used on many places with attribute id value.

I tried to create new attribute with same name but it is having auto increment value in eav_attribute table which is creating attribute with different id.

I have also query to set auto_increment before adding new attribute

alter table eav_attribute auto_increment = 961;

But it is not working in my case. Please provide any suggestion that How can I create a new attribute with same attribute id.


1 Answer 1


Just create the attribute with the attribute_code you'd want, then go to the eav_attribute table, search for your attribute_code, and change its ID to your desired one.

UPDATE eav_attribute set attribute_id = YOUR_ID where attribute_code = 'ATTRIBUTE_CODE'

There should not be any problem, magento has foreign keys for eav attributes, the only problem might be the custom tables that use attribute ids and does not have foreign keys on the attribute id

For future references. Don't use the attribute_id in your code. Use the attribute_code, all eav attributes in magento 2 have support for the attribute_code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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