Question

I inserted 2 category attributes using a module with the file mysql4-install-0.1.0.php in a sql folder:

$installer = $this;

$installer->startSetup();

$installer->addAttribute('catalog_category', 'short_description', array(
    'type'          => 'text',
    'label'         => 'Short Description',
    'input'         => 'textarea',
    'group'         => 'General',
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'       => true,
    'required'      => false
));
$installer->addAttribute('catalog_category', 'static_block', array(
    'type'          => 'text',
    'label'         => 'Brand',
    'input'         => 'text',
    'group'         => 'General',
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'       => true,
    'required'      => false
));

$this->endSetup();

How can I delete them now. I tried inserting this in the sql file, as suggested in other answers:

$installer = $this;
$installer->startSetup();
$installer->removeAttribute('catalog_category', 'short_description');
$installer->removeAttribute('catalog_category', 'static_block');
$installer->endSetup();

But nothing happens. Should I create another module?

Was it helpful?

Solution

You need to create a different upgrade script.
If the install script has the version 0.1.0 create the file upgrade-0.1.0-0.1.1.php with this content:

$installer = $this;
$installer->removeAttribute('catalog_category', 'short_description');
$installer->removeAttribute('catalog_category', 'static_block');

Then go to config.xml and change the version tag from 0.1.0 to 0.1.1.

Clear the cache and refresh any page.

As a side node...don't use $installer->startSetup(); in install/upgrade scripts that remove data. Calling it, disables the foreign key checks and you might end up with zombie data in your db.

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