Repository navigation
Open
Milestone
Description
Example code:
CREATE TABLE IF NOT EXISTS banks (
name STRING PRIMARY KEY,
is_open BOOLEAN DEFAULT true,
[key] STRING
);
CREATE TABLE IF NOT EXISTS pigs (
id STRING PRIMARY KEY,
bank STRING REFERENCES banks(name)
ready BOOLEAN,
dream STRING,
notes STRING,
kind STRING,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);Result:
/home/raskolnikov/dev/cerditos/server/node_modules/alasql/dist/alasql.fs.js:12518
if (fktable.pk.columns && fktable.pk.columns.length > 0) {
^
TypeError: Cannot read properties of undefined (reading 'columns')
at /home/raskolnikov/dev/cerditos/server/node_modules/alasql/dist/alasql.fs.js:12518:21
at Array.forEach (<anonymous>)
at yy.CreateTable.execute (/home/raskolnikov/dev/cerditos/server/node_modules/alasql/dist/alasql.fs.js:12452:11)
at adrunone (/home/raskolnikov/dev/cerditos/server/node_modules/alasql/dist/alasql.fs.js:4811:16)
at FS.createTable (/home/raskolnikov/dev/cerditos/server/node_modules/alasql/dist/alasql.fs.js:18892:10)
at yy.CreateTable.execute (/home/raskolnikov/dev/cerditos/server/node_modules/alasql/dist/alasql.fs.js:12662:38)
at adrunone (/home/raskolnikov/dev/cerditos/server/node_modules/alasql/dist/alasql.fs.js:4811:16)
at alasql.adrun (/home/raskolnikov/dev/cerditos/server/node_modules/alasql/dist/alasql.fs.js:4819:2)
at alasql.dexec (/home/raskolnikov/dev/cerditos/server/node_modules/alasql/dist/alasql.fs.js:4731:11)
at alasql.exec (/home/raskolnikov/dev/cerditos/server/node_modules/alasql/dist/alasql.fs.js:4664:17)
Node.js v18.18.2
I have tried with LOCALSTORAGE instead and the forementioned code seems to work. I don't think that foreign key rules are actually being applied though.
This alternative syntax seems to be working, but also it seems that the constraint is simply ignored:
CREATE TABLE IF NOT EXISTS pigs (
id STRING PRIMARY KEY,
bank STRING,
ready BOOLEAN,
dream STRING,
notes STRING,
kind STRING,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (bank) REFERENCES bank(name)
);Reacted by Gary Gurlaskie
Activity
leolalopeslobo commentedon Mar 30, 2026
Hi, I’d like to work on this issue. Is it okay if I take it?
mathiasrw commentedon Apr 1, 2026
@leolalopeslobo Please!
Yashmishra06 commentedon May 13, 2026
I'd love to help move this forward — could @mathiasrw assign this issue to me?
mathiasrw commentedon Sep 10, 2026
@Yashmishra06 Any news on this?
Fix REFERENCES crash with FILESTORAGE to address AlaSQL#1846
jsingh0026 commentedon Oct 21, 2026
Hi @mathiasrw 👋
Since there had been no activity here for a while, I picked this up and opened #2798 for the crash part of this issue.
What it fixes:
TypeError: Cannot read properties of undefined (reading 'columns')onbank STRING REFERENCES banks(name)in FILESTORAGE. AfterATTACH, the live tables were the same object as the schema stored in the file, so everyCREATE TABLEdropped the other tables' primary keys.REFERENCES banks(name)was ignored, and the primary key was always used. That is why it also crashed after attaching the database again, e.g. withCREATE TABLE IF NOT EXISTSon each app start.What it does not fix: the constraint still isn't enforced on FILESTORAGE inserts. With
autocommiton, engine inserts skip all of the table's checks. That's the cause described in #2681 / #2725, so this issue should probably stay open until that's done.