Removing a custom attribute in Magento via an installer script

magento, magento-1.7

Solution

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$custAttr = 'is_school'; 

 $setup->removeAttribute('customer', $custAttr);
 $setup->endSetup();

Please check `class Mage_Eav_Model_Entity_Setup extends Mage_Core_Model_Resource_Setup`

In

public function removeAttribute($entityTypeId, $code)
{
    $mainTable  = $this->getTable('eav/attribute');
    $attribute  = $this->getAttribute($entityTypeId, $code);
    if ($attribute) {
        $this->deleteTableRow('eav/attribute', 'attribute_id', $attribute['attribute_id']);
        if (isset($this->_setupCache[$mainTable][$attribute['entity_type_id']][$attribute['attribute_code']])) {
            unset($this->_setupCache[$mainTable][$attribute['entity_type_id']][$attribute['attribute_code']]);
        }
    }
    return $this;
}

It takes two arguments - the first is the `entity code`, and the second is the `attribute code`.

Problem

I have the following code in an installer script & need to now remove the is_school attribute via the installer script, is my code correct? ``` // code within existing installer script (this works fine) $installer->addAttribute("customer", "is_school", array( "type" => "int", "backend" => "", "label" => "Is School?", "input" => "int", "source" => "", "visible" => false, "required" => false, "default" => "", "frontend" => "", "unique" => false, "note" => "" )); ``` My intended approach to remove the attribute - does this look correct? ``` $installer->startSetup(); $installer->removeAttribute('customer', 'is_school'); $installer->endSetup(); ``` Is there anything else required when removing attributes?

Original source