Question

I want to remove unused EAV attributes directly from the database before I move my store live. Attributes can be found in eav_attribute table, can I delete attributes from this table? Is it safe? Or do I also need to edit other EAV tables?

Was it helpful?

Solution

See Mage_Eav_Model_Entity_Setup::removeAttribute(). It takes two arguments - the first is the entity code, and the second is the attribute code.

Edit - to run from a non-installation scope:

<?php
include 'app/Mage.php';
Mage::app();
$setup = Mage::getResourceModel('catalog/setup','catalog_setup');
$setup->removeAttribute('catalog_product','attr_code');

OTHER TIPS

The first rule of Magento is: Never edit the database directly.
I admit that I broke this rule on numerous occasions, so...
you can delete the attributes from eav_attribute, the constraints with ON DELETE CASCADE should cleanup the rest of the tables.
But I still think you should take the clean way:

$attributeId = 55;
Mage::getModel('catalog/resource_eav_attribute')->load($attributeId)->delete();

It shouldn't take long and you will feel at peace with yourself because you didn't break the rules.
It's not important what method you choose, but backing up your DB is, in both cases.

DELETE FROM eav_attribute WHERE eav_attribute.attribute_code = "some_attr_code";

is a working solution, I used it many times.

Especially if you remove extension and Magento still want to call unexisting attribute model

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top