title: magento mysql setup file in custom extension
body: <p>i have an extension in magento that when installed works fine but when i reset/restart the extension (as i have added more attributes, functions that only show up when you reload the extension) by removing the core_resource in the database and i have used this technique before for another module and worked fine but this extension is giving me an error</p>
  
  <p>So I get massive error across the whole site and so i check the var/report and it says there is an error in the setup file from the extension (as its trying to reload the setup file but it must have something to do with the creation or overwriting of the tables that are created the first time but are not deleted in the database as they should remain because it is data that has been saved and removal of these tables would result in entering the data again</p>
  
  <p>so please see below the setup file that seems to be causing the issue</p>
  
  <pre><code>&lt;?php
  
  $installer = $this;
  /* @var $installer Mage_Core_Model_Resource_Setup */
  
  $installer-&gt;startSetup();
  $installer-&gt;run("
  CREATE TABLE IF NOT EXISTS `customerpartner_aux` (
    `id` INT(11)  NOT NULL AUTO_INCREMENT,
    `product_id` INT(11)  NOT NULL,
    `order_id` INT(11)  NOT NULL,
    `real_order_id` INT(11)  NOT NULL,
    `quantity` INT(11)  NOT NULL,
    `percent` DECIMAL(10,2)  NOT NULL,
    `amount_earned` DECIMAL(10,2)  NOT NULL,
    `amount_owed` DECIMAL(10,2)  NOT NULL,
    `cleared_at` DATETIME NOT NULL,
    PRIMARY KEY (`id`)
  )
  ENGINE=InnoDB DEFAULT CHARSET=utf8;
  
  CREATE TABLE IF NOT EXISTS `{$this-&gt;getTable('customerpartner_entity')}` (
    `entity_id` int(10) unsigned NOT NULL auto_increment,
    `entity_type_id` smallint(8) unsigned NOT NULL default '0',
    `attribute_set_id` smallint(5) unsigned NOT NULL default '0',
    `website_id` smallint(5) unsigned default NULL,
    `email` varchar(255) NOT NULL default '',
    `group_id` smallint(3) unsigned NOT NULL default '0',
    `increment_id` varchar(50) NOT NULL default '', `parent_id` int(10) unsigned NOT NULL default '0',
    `store_id` smallint(5) unsigned default '0',
    `created_at` datetime NOT NULL default '0000-00-00 00:00:00',
    `updated_at` datetime NOT NULL default '0000-00-00 00:00:00',
    `is_active` tinyint(1) unsigned NOT NULL default '1',
    PRIMARY KEY  (`entity_id`),
    KEY `FK_CUSTOMERPARTNER_ENTITY_STORE` (`store_id`),
    KEY `IDX_ENTITY_TYPE` (`entity_type_id`),
    KEY `IDX_AUTH` (`email`,`website_id`),
    KEY `FK_CUSTOMERPARTNER_WEBSITE` (`website_id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Customer Entityies' AUTO_INCREMENT=1 ;
  
  
  CREATE TABLE IF NOT EXISTS `{$this-&gt;getTable('customerpartner_entity_datetime')}` (
    `value_id` int(11) NOT NULL auto_increment,
    `entity_type_id` smallint(8) unsigned NOT NULL default '0',
    `attribute_id` smallint(5) unsigned NOT NULL default '0',
    `entity_id` int(10) unsigned NOT NULL default '0',
    `value` datetime NOT NULL default '0000-00-00 00:00:00',
    PRIMARY KEY  (`value_id`),
    KEY `FK_CUSTOMERPARTNER_DATETIME_ENTITY_TYPE` (`entity_type_id`),
    KEY `FK_CUSTOMERPARTNER_DATETIME_ATTRIBUTE` (`attribute_id`),
    KEY `FK_CUSTOMERPARTNER_DATETIME_ENTITY` (`entity_id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  
  CREATE TABLE IF NOT EXISTS `{$this-&gt;getTable('customerpartner_entity_decimal')}` (
    `value_id` int(11) NOT NULL auto_increment,
    `entity_type_id` smallint(8) unsigned NOT NULL default '0',
    `attribute_id` smallint(5) unsigned NOT NULL default '0',
    `entity_id` int(10) unsigned NOT NULL default '0',
    `value` decimal(12,4) NOT NULL default '0.0000',
    PRIMARY KEY  (`value_id`),
    KEY `FK_CUSTOMERPARTNER_DECIMAL_ENTITY_TYPE` (`entity_type_id`),
    KEY `FK_CUSTOMERPARTNER_DECIMAL_ATTRIBUTE` (`attribute_id`),
    KEY `FK_CUSTOMERPARTNER_DECIMAL_ENTITY` (`entity_id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  
  CREATE TABLE IF NOT EXISTS `{$this-&gt;getTable('customerpartner_entity_int')}` (
    `value_id` int(11) NOT NULL auto_increment,
    `entity_type_id` smallint(8) unsigned NOT NULL default '0',
    `attribute_id` smallint(5) unsigned NOT NULL default '0',
    `entity_id` int(10) unsigned NOT NULL default '0',
    `value` int(11) NOT NULL default '0',
    PRIMARY KEY  (`value_id`),
    KEY `FK_CUSTOMERPARTNER_INT_ENTITY_TYPE` (`entity_type_id`),
    KEY `FK_CUSTOMERPARTNER_INT_ATTRIBUTE` (`attribute_id`),
    KEY `FK_CUSTOMERPARTNER_INT_ENTITY` (`entity_id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  
  CREATE TABLE IF NOT EXISTS `{$this-&gt;getTable('customerpartner_entity_text')}` (
    `value_id` int(11) NOT NULL auto_increment,
    `entity_type_id` smallint(8) unsigned NOT NULL default '0',
    `attribute_id` smallint(5) unsigned NOT NULL default '0',
    `entity_id` int(10) unsigned NOT NULL default '0',
    `value` text NOT NULL,
    PRIMARY KEY  (`value_id`),
    KEY `FK_CUSTOMERPARTNER_TEXT_ENTITY_TYPE` (`entity_type_id`),
    KEY `FK_CUSTOMERPARTNER_TEXT_ATTRIBUTE` (`attribute_id`),
    KEY `FK_CUSTOMERPARTNER_TEXT_ENTITY` (`entity_id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  
  CREATE TABLE IF NOT EXISTS `{$this-&gt;getTable('customerpartner_entity_varchar')}` (
    `value_id` int(11) NOT NULL auto_increment,
    `entity_type_id` smallint(8) unsigned NOT NULL default '0',
    `attribute_id` smallint(5) unsigned NOT NULL default '0',
    `entity_id` int(10) unsigned NOT NULL default '0',
    `value` varchar(255) NOT NULL default '',
    PRIMARY KEY  (`value_id`),
    KEY `FK_CUSTOMERPARTNER_VARCHAR_ENTITY_TYPE` (`entity_type_id`),
    KEY `FK_CUSTOMERPARTNER_VARCHAR_ATTRIBUTE` (`attribute_id`),
    KEY `FK_CUSTOMERPARTNER_VARCHAR_ENTITY` (`entity_id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  
  ALTER TABLE `{$this-&gt;getTable('customerpartner_entity')}`
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_ENTITY_STORE` FOREIGN KEY (`store_id`) REFERENCES `{$this-&gt;getTable('core_store')}` (`store_id`) ON DELETE SET NULL ON UPDATE CASCADE,
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_WEBSITE` FOREIGN KEY (`website_id`) REFERENCES `{$this-&gt;getTable('core_website')}` (`website_id`) ON DELETE SET NULL ON UPDATE CASCADE;
  
  
  ALTER TABLE `{$this-&gt;getTable('customerpartner_entity_datetime')}`
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_DATETIME_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$this-&gt;getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_DATETIME_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `{$this-&gt;getTable('customerpartner_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_DATETIME_ENTITY_TYPE` FOREIGN KEY (`entity_type_id`) REFERENCES `{$this-&gt;getTable('eav_entity_type')}` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE;
  
  ALTER TABLE `{$this-&gt;getTable('customerpartner_entity_decimal')}`
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_DECIMAL_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$this-&gt;getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_DECIMAL_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `{$this-&gt;getTable('customerpartner_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_DECIMAL_ENTITY_TYPE` FOREIGN KEY (`entity_type_id`) REFERENCES `{$this-&gt;getTable('eav_entity_type')}` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE;
  
  ALTER TABLE `{$this-&gt;getTable('customerpartner_entity_int')}`
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_INT_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$this-&gt;getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_INT_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `{$this-&gt;getTable('customerpartner_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_INT_ENTITY_TYPE` FOREIGN KEY (`entity_type_id`) REFERENCES `{$this-&gt;getTable('eav_entity_type')}` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE;
  
  ALTER TABLE `{$this-&gt;getTable('customerpartner_entity_text')}`
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_TEXT_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$this-&gt;getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_TEXT_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `{$this-&gt;getTable('customerpartner_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_TEXT_ENTITY_TYPE` FOREIGN KEY (`entity_type_id`) REFERENCES `{$this-&gt;getTable('eav_entity_type')}` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE;
  
  ALTER TABLE `{$this-&gt;getTable('customerpartner_entity_varchar')}`
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_VARCHAR_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$this-&gt;getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_VARCHAR_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `{$this-&gt;getTable('customerpartner_entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `FK_CUSTOMERPARTNER_VARCHAR_ENTITY_TYPE` FOREIGN KEY (`entity_type_id`) REFERENCES `{$this-&gt;getTable('eav_entity_type')}` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE;
      ");
  
  $installer-&gt;installEntities();
  
  $installer-&gt;endSetup();  
  </code></pre>
  
  <p>so any help would be very appreciated as this is for an open source community project and really can't go any further until I'm able to reset/reload the extension anytime (to easily add attributes etc) without having to delete every table and entity in the database resulting in all loss of all the data input by users which would be huge over time.</p>
  
  <p>I'll also be trying to debug this until its fixed</p>
  
  <p>cheers</p>
  
  <p>nz warrior</p>