I have an issue an unsure if this a bug or not.
I created a test database (SQLite) as follows:
-- DataBase example
CREATE TABLE artist(
artistid INTEGER PRIMARY KEY,
artistname TEXT
);
CREATE TABLE track(
trackid INTEGER,
trackname TEXT,
trackartist INTEGER -- Must map to an artist.artistid!
FOREIGN KEY(trackartist) REFERENCES artist(artistid)
);
If I try to delete an entry from the artist table, that has been used in the track table, then SQLite throws an error: [18:10:46] Error while executing SQL query on database 'test2': FOREIGN KEY constraint failed. This is what I expect.
Now I try to delete this via Node-Red, and it happily deletes the entry, even while I have the foreign key constraint. I did try setting the "PRAGMA foreign_keys = 1" in the database without avail. Am I missing something or is this a bug?
Test code below:
[{"id":"833221a7.dc2c8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"ef90ba5c.668768","type":"inject","z":"833221a7.dc2c8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":300,"wires":[["e3e9e7d2.56a9f8"]]},{"id":"2eac59af.e497c6","type":"debug","z":"833221a7.dc2c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":810,"y":300,"wires":[]},{"id":"72ee0096.7c029","type":"complete","z":"833221a7.dc2c8","name":"","scope":["16b53d78.419833"],"uncaught":false,"x":520,"y":350,"wires":[["d6b09823.132738"]]},{"id":"d6b09823.132738","type":"debug","z":"833221a7.dc2c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":350,"wires":[]},{"id":"da1b8b79.b204d8","type":"catch","z":"833221a7.dc2c8","name":"","scope":["72ee0096.7c029","e3e9e7d2.56a9f8"],"uncaught":false,"x":500,"y":400,"wires":[["2d6333dd.56a36c"]]},{"id":"2d6333dd.56a36c","type":"debug","z":"833221a7.dc2c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":400,"wires":[]},{"id":"8959a77a.24d018","type":"comment","z":"833221a7.dc2c8","name":"Data Base example inside","info":"-- DataBase example\n\nCREATE TABLE artist(\n artistid INTEGER PRIMARY KEY, \n artistname TEXT\n);\nCREATE TABLE track(\n trackid INTEGER,\n trackname TEXT, \n trackartist INTEGER -- Must map to an artist.artistid!\n FOREIGN KEY(trackartist) REFERENCES artist(artistid)\n);","x":330,"y":200,"wires":[]},{"id":"e3e9e7d2.56a9f8","type":"sqlite","z":"833221a7.dc2c8","mydb":"70ad58fe.56e7b8","sqlquery":"fixed","sql":"PRAGMA foreign_keys = ON;\ndelete from artist\nwhere artistid = 3","name":"test","x":500,"y":300,"wires":[["2eac59af.e497c6"]]},{"id":"70ad58fe.56e7b8","type":"sqlitedb","z":"","db":"D:\\DBase\\test2.db","mode":"RWC"}]