yiisoft / yiisoft/db-migration

SQLite does not support addForeignKey()

Open
#218 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
32
Forks
18
Avg merge
22h 18m
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the yii migrate:create command against SQLite, then inspect resources/views/_createTable.php at the linked lines and compare its generated SQL with SQLite's foreign-key syntax. Done means the command no longer throws an exception and the generated CREATE TABLE query includes the requested foreign-key constraint.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sqlite
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.