0

In magento i created a custom module and completed the template and controller part, but confused about handling the model and db part. From my custom module i want to alter the table sales_flat_order_item and add an additional field. Now i created a set up script like

$installer = $this;
$installer->startSetup();
$installer->run("
ALTER TABLE sales_flat_order_item ADD COLUMN new_field TEXT NULL;

ALTER TABLE sales_flat_invoice_item ADD COLUMN new_field TEXT NULL;

ALTER TABLE sales_flat_shipment_item ADD COLUMN new_field TEXT NULL;
");
$installer->endSetup(); 

in path app\code\local\Namespace\Module\sql\_setup\mysql4-install-0.1.0.php But the table is not seems to be altered what configuration can be done in the script or module files to add the additional field and processing data with the same like the other fields. any one help. Thanks.

1
  • What version of magento are you using? Jul 30, 2012 at 7:52

2 Answers 2

1

what is your config.xml configuration looks like?

under <global></global> tag you need to add:

<resources>
    <sql_setup>
        <setup>
            <module>Namespace_Module</module>
        </setup>
    </sql_setup>
</resources>
6
  • Sorry to say, Added this in config files but no result.
    – Soji
    Jul 30, 2012 at 7:02
  • can you post all of your config.xml file? also please check your database: select * from core_resource where code like 'sql_setup';
    – ivantedja
    Jul 30, 2012 at 7:11
  • The given query returns one row, with code: sql_setup, version: 0.4.0,data_version: 0.4.0
    – Soji
    Jul 30, 2012 at 7:20
  • It means your current modules's version is 0.4.0. You can do upgrade but not install. If you're going to do install, you need to delete the value in core_resource (delete from core_resource where code like 'sql_setup') and change your module's version into 0.1.0 (<version>0.1.0</version>)
    – ivantedja
    Jul 30, 2012 at 7:23
  • Create file under sql_setup, eg: mysql4-upgrade-0.4.0-0.5.0.php and then you need to change your module's version into 0.5.0. That means you're upgrading it from version 0.4.0 into version 0.5.0
    – ivantedja
    Jul 30, 2012 at 7:33
0

try to put something like this

 $installer->run("
ALTER TABLE {$this->getTable('sales_flat_shipment_item')} ADD `new_field` TEXT NULL ;
");
2
  • Tried this but not worked for me. Is there any changes needed in model files or config xml? any idea?
    – Soji
    Jul 30, 2012 at 6:44
  • Yes the version value is changed.
    – Soji
    Jul 30, 2012 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.