0

Hello I'm struggling to get an upgrade script working. Here is my script:

$installer = $this;
$installer->startSetup();
// Update table
$installer->getConnection()
->addColumn($installer->getTable('mymodelalias'),
 'new_column1',
 array(
 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
 'length' => 1,
 'nullable' => false,
 'default' => 0,
 'comment' => 'My Column 1')
)
->addColumn($installer->getTable('mymodelalias'), 
 'new_column2',
 array(
 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
 'nullable' => true,
 'comment' => 'My Column 2')
)
->addColumn($installer->getTable('mymodelalias'), 
 'new_column3',
 array(
 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
 'length' => 100,
 'nullable' => true,
 'comment' => 'My Column 3')
)
->addColumn($installer->getTable('mymodelalias'), 
 'new_column4',
 array(
 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
 'length' => 255,
 'nullable' => true,
 'comment' => 'My Column 4')
);
$installer->endSetup();

I get this error

Call to undefined method Varien_Db_Statement_Pdo_Mysql::addColumn() in "/Users/myname/app/code/local/Myvendor/Mymodule/sql/myvendor_mymodule_setup/upgrade-0.1.0.2-0.1.0.3.php" line 19

Any idea what's the issue?

Manashvi Birla
8,8739 gold badges29 silver badges53 bronze badges
asked Apr 26, 2016 at 14:04
1
  • show your config.xml Commented Apr 26, 2016 at 14:22

1 Answer 1

1

I realised that calling $installer->getConnection() for each column made it working.

$installer = $this;
$installer->startSetup(); 
$installer->getConnection()
 ->addColumn($installer->getTable('mymodelalias'),
 'mycolumn1',
 array(
 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
 'length' => 1,
 'nullable' => false,
 'default' => 0,
 'comment' => 'My Column 1')
);
$installer->getConnection()
 ->addColumn($installer->getTable('mymodelalias'),
 'mycolumn2',
 array(
 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
 'nullable' => true,
 'comment' => 'My Column 2')
);

etc..

 $installer->endSetup();
answered Apr 26, 2016 at 14:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.