i'm trying to add a foreign key to my table, but when i try to do that i receive the:
Adding a foreign key constraint to an existing table is not supported by SQLite.
$this->addForeignKey('fk_user', 'tbl_data', 'id_responsable','tbl_user', 'id', 'CASCADE');
$this->createTable('tbl_data', array(
'id' => 'pk',
'name' => 'string',
'id_responsable' => 'integer',
));
This is intended behaviour, see source: https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php#L242
public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete=null, $update=null)
{
throw new CDbException(Yii::t('yii', 'Adding a foreign key constraint to an existing table is not supported by SQLite.'));
}
I'm assuming this is attempting to be portable code across different DBMSs ( if it's not and is meant to only work on sqlite, just don't put the call there :p )
If you wanted to override this functionality you'd have to extend the Sqlite Schema class, and then your into a world of trouble.
You might be better off in your situation switching off the add foreign key, based on the Yii::app()->db->driverName. If it == sqlite then don't add the foreign key.
Or do some hack doogery to save the table, recreate it with the foreign key, and load all data back in again.