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.

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.

New contributor
QuietGeek is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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