Jonathon Day says
\"updates SHOULD NOT be in the form of SQL commands\". I haven\'t come across any DDL or DML statments that cannot be executed
To alter table and add column with a foreign key, I have used this successfully using Magento CE v1.6.1.0 :
// Alter table to add column
$installer->getConnection()
->addColumn(
$installer->getTable('modulekey/model'),
'column_name',
array(
'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
'length' => null,
'unsigned' => true,
'nullable' => true,
'comment' => 'Foreign key'
)
);
// Add foreign key constraint
$installer->getConnection()
->addForeignKey(
$installer->getFkName(
'modulekey/model', 'column_name',
'modulekey/foreign_model', 'foreign_column_name'
),
$installer->getTable('modulekey/model'),
'column_name',
$installer->getTable('modulekey/foreign_model'),
'foreign_column_name',
Varien_Db_Ddl_Table::ACTION_SET_NULL,
Varien_Db_Ddl_Table::ACTION_SET_NULL
);
Those are methods from Varien_Db_Adapter_Pdo_Mysql
.