1

I used following method and it's working fine for me.

 <?php 
 $installer = $this;
 $installer->startSetup();

 $installer->addAttribute("order", "barcode", array("type"=>"varchar","default"=>"N/A"));
 $installer->addAttribute("quote", "barcode", array("type"=>"varchar","default"=>"N/A"));

 $installer->endSetup();
 ?>

But How I can achieve it with following method ?

 <?php  
 $installer = $this;
 $installer->startSetup();
 $installer->run("ALTER TABLE  sales_flat_order ADD COLUMN barcode  VARCHAR(255) NOT NULL;");
 $installer->run("ALTER TABLE  sales_flat_order_grid ADD COLUMN barcode  VARCHAR(255) NOT NULL;");
 $installer->run("ALTER TABLE  sales_flat_quote ADD COLUMN barcode  VARCHAR(255) NOT NULL;");

 $installer->endSetup();
 ?>
0

2 Answers 2

1

The installer should come with a method modifyColumn. This will allow you to modify an existing column in any table.

The method requires you to pass in the table name, column name and the new definition.

For example in app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.0-1.4.0.0.1.php you can see the modification of some catalog product tables.

$installer->getConnection()->modifyColumn($installer->getTable('catalog/product') . '_int', 'value', 'int(11) default NULL');
1
  • ->modifyColumn(tablename . '?', '?', 'changes'); in here which is column name and what is another one method
    – ND17
    Oct 16, 2015 at 11:55
0

Try

$installer = $this;

$installer->startSetup();


$installer->run("
    ALTER TABLE `{$installer->getTable('sales_flat_order')}` ADD COLUMN  `barcode` VARCHAR( 255 )  NOT NULL DEFAULT 'N/A' ;
    ALTER TABLE `{$installer->getTable('sales_flat_order_grid')}` ADD COLUMN `barcode` VARCHAR( 255 )  NOT NULL DEFAULT 'N/A';
    ALTER TABLE `{$installer->getTable('sales_flat_quote')}` ADD COLUMN `barcode` VARCHAR( 255 )  NOT NULL DEFAULT 'N/A';
");

$installer->endSetup();
3
  • Not working.... Oct 29, 2014 at 9:50
  • Is this a MySql db? Oct 29, 2014 at 12:18
  • 1
    Please explain 'not working'... are you getting an error or does it run perfect but nothing happen? Did you make the necessary changes in core_resource so the script would run again. How are you testing to see if the table column are there? Oct 29, 2014 at 13:12

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.