Skip to content

SQLite does not support addForeignKey() #218

@Tigrov

Description

@Tigrov

SQLite does not support addForeignKey() but supports foreign key constraints inside columns definitions of CREATE TABLE query.

https://www.sqlite.org/foreignkeys.html

CREATE TABLE track(
  trackid     INTEGER, 
  trackname   TEXT, 
  trackartist INTEGER,
  FOREIGN KEY(trackartist) REFERENCES artist(artistid)
);

The follow command throws an Exception in SQLite

./yii migrate:create post --command=table --fields='department_id:integer:notNull:foreignKey(department)'

Due to column foreign key is initialized separately

echo " \$b->createTable('$table', [\n";
foreach ($columns as $column) {
if (!$column->hasDecorators()) {
echo " '{$column->getProperty()}',\n";
} else {
echo " '{$column->getProperty()}' => \$b->{$column->getDecoratorsString()},\n";
}
}
echo " ]);\n";
echo $this->render(__DIR__ . '/_addForeignKeys.php', [
'table' => $table,
'foreignKeys' => $foreignKeys,
]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions