How do I rename an attribute code in Magento?

user9903 picture user9903 · Mar 4, 2011 · Viewed 17.5k times · Source

I want to rename an existing attribute's code to something else. The reason is because the attribute field is filled out for 300+ products and I don't want to have to re-import all of those just because I changed the code of an attribute.

Answer

Jan Wy picture Jan Wy · Jun 15, 2011

It is much easier to use an upgrade script with the following content for that:

$installer = $this;
$installer->startSetup();
$installer->updateAttribute('catalog_product', 'old_attribute_code', array('attribute_code' => 'new_attribute_code'));
$installer->endSetup();