Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite does not support addForeignKey() #218

Open
Tigrov opened this issue Oct 17, 2023 · 0 comments
Open

SQLite does not support addForeignKey() #218

Tigrov opened this issue Oct 17, 2023 · 0 comments

Comments

@Tigrov
Copy link
Member

Tigrov commented Oct 17, 2023

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,
]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant