I want to prevent error that column in database table exits.
How can I add column to table only if column does not exist?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityYou can use this to check if table column exists.
$installer = $this;
$installer->startSetup();
$connection = $installer->getConnection();
$tableName = $installer->getTable('your_table_name');
$columnName = 'testcolumn';
if ($connection->tableColumnExists($tableName, $columnName) === false) {
$connection->addColumn($tableName, $columnName, array(
'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
'nullable' => false,
'length' => 255,
'after' => null, // column name to insert new column after
'comment' => 'Title'
));
}