Add Foreign Key
/** @var Mage_Core_Model_Resource_Setup $installer */
$installer = $this;
$installer->startSetup();
/** @var Varien_Db_Adapter_Pdo_Mysql $connection */
$connection = $installer->getConnection();
$table = $installer->getTable('simple/box');
$column = 'clinic_id';
if (!$connection->tableColumnExists($table, $column)) {
$connection->addColumn($table, $column, [
'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
'unsigned' => true,
'nullable' => true,
'comment' => 'Clinic Id',
'after' => 'entity_id' // insert after this col
]);
$connection->addForeignKey(
$installer->getFkName('simple/box', $column, 'customer/entity', 'entity_id'),
$table,
$column,
$installer->getTable('customer/entity'),
'entity_id'
);
}
$installer->endSetup();
Change Column Name
$connection->changeColumn(
$table,
$oldColName,
$newColName,
[
'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
'unsigned' => true,
'comment' => 'Box ID'
]
);
Add Column Type varchar
and Index
/** @var Mage_Core_Model_Resource_Setup $installer */
$installer = $this;
$installer->startSetup();
$connection = $installer->getConnection();
$table = $installer->getTable('sales/order_grid');
if (!$connection->tableColumnExists($table, 'skus')) {
/* Error: TEXT column 'value' used in key specification without a key length
$connection->addColumn($table, 'skus', [
'type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
'nullable' => true,
'length' => 767,
'comment' => 'SKUs'
]);
*/
// To fix : hard define varchar(767)
$connection->addColumn(
$table,
'skus',
'varchar(767) DEFAULT NULL'
);
}
$connection->addIndex(
$table,
$installer->getIdxName($table, ['skus']),
['skus'],
Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
);
$installer->endSetup();
Posted by kiatng to OpenMage (2021-08-28 06:52)