How to update the attribute code of the attribute in magento 2.

I have refered below link https://stackoverflow.com/questions/5198266/how-do-i-rename-an-attribute-code-in-magento


Once the attribute code has been created, it cannot be edited through the admin or API. This is because Magento uses it as an internal identifier. It is never displayed anywhere (neither frontend nor backend) other than the Manage Attributes section of the admin.

You could try editing it directly in the database, as noted in the linked answer, but this will break any extensions, custom development, etc which relies on that code. Magento will very likely be confused as well, which may lead to data corruption.

If the attribute is a custom one (not a system one) your best bet is to delete the attribute and create a new one with your new attribute code.

If the attribute is a system one (i.e. Created by Magento when you installed it) then I would strongly recommend not changing it - some attribute codes are hardcoded in the source code, e.g. In interfaces. You will break a lot of things.

  • Any ideas on what exactly can break in Magento? and where exactly the codes are used? We may need to do this and deleting and creating a new one is not an option because we already have products using the attribute. – Jorjani Dec 19 '18 at 13:32

Since I can't comment yet (not enough reputation), I just want to note that the attribute code does actually appear to the user - specifically, when you filter a product list the attribute code is used in the URL. So it does help to have meaningful (and appropriate) code names.

For myself when solving the same problem with a custom attribute (why I found this topic), I solved the issue by manually editing the database. Editing the attribute_code field in the eav_attribute table and flushing the cache is enough to resolve this.

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.