You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: SQLite describeReferences() gives null referenced columns for a key with no referenced columns #17815
Describe the bug
SQLite accepts a foreign key with no referenced columns, for example REFERENCES users. The key then points to the primary key of users. PRAGMA foreign_key_list gives null in column 4 (to) for such a key.
Phalcon\Db\Adapter\Pdo\Sqlite::describeReferences() copies that null into referencedColumns. The reference then has no referenced column.
To Reproduce
SQLite 3.46.1:
CREATETABLEusers (id INTEGERPRIMARY KEY);
CREATETABLEcustomers (a INT, b INT, PRIMARY KEY (a, b));
CREATETABLEorders (
id INTEGERPRIMARY KEY,
cust INTREFERENCES users
);
CREATETABLEnotes (
x INT,
y INT,
FOREIGN KEY (x, y) REFERENCES customers
);
The fix: when to is null, use the primary key of the referenced table. PRAGMA table_info('<referenced table>') gives the primary key columns: the rows with pk > 0, in the order of pk. Match them to the columns of the key by seq.
Additional context
Found in phalcon/crest#87: crest make:model cannot write a relation for such a key. It skips it with the reason the key does not name the referenced columns.
Activity
niden commentedon Nov 27, 2026
Resolved in #17819
[phalcon#17815] - using the primary key of the referenced table for a…
[phalcon#17815] - updating changelog and ext