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();
 ?>
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');
  • ->modifyColumn(tablename . '?', '?', 'changes'); in here which is column name and what is another one method – ND17 Oct 16 '15 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();
  • Not working.... – Praful Rajput Oct 29 '14 at 9:50
  • Is this a MySql db? – Renon Stewart Oct 29 '14 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? – Renon Stewart Oct 29 '14 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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