1

How can I add a column before or after a particular column in existing table.

Let suppose I want to add email id after a column named as telephone.

Is it possible with some parameter in following code?

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

        $installer->getConnection()
        ->addColumn($installer->getTable('contactus'),'emailid', array(
            'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
            'nullable'  => false,
            'length'    => 254,
            'comment'   => 'emailid'    
            ));
        $installer->endSetup();
Teja Bhagavan Kollepara
  • 3,816
  • 5
  • 32
  • 69
Mukesh
  • 1,428
  • 4
  • 28
  • 58

1 Answers1

3
$installer = $this;
$installer->startSetup();

$installer->getConnection()
    ->addColumn($installer->getTable('contactus'),'emailid', array(
        'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
        'nullable'  => false,
        'length'    => 254,
        'comment'   => 'emailid'
        'after'     => '[column_name]'   
    ));
$installer->endSetup();
SeStro
  • 774
  • 5
  • 16