db-migration icon indicating copy to clipboard operation
db-migration copied to clipboard

SQLite does not support addForeignKey()

Open Tigrov opened this issue 2 years ago • 0 comments

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

https://github.com/yiisoft/db-migration/blob/940d9885aa17c273d7e3980f9730d220b6830658/resources/views/_createTable.php#L14-L26

Tigrov avatar Oct 17 '23 06:10 Tigrov