'On delete cascade on foreign key not working [duplicate]
I am doing a TODO list app and I'm trying to delete a list and every task which has the referencing listID.The problem is that on delete cascade is not working and when I delete the list the tasks are still there. This is my code:
CREATE TABLE IF NOT EXISTS Lists(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT
)
CREATE TABLE IF NOT EXISTS Tasks(
id INTEGER PRIMARY KEY AUTOINCREMENT,
txt TEXT,
listID INTEGER,
completed BOOLEAN NOT NULL DEFAULT 0,
FOREIGN KEY (listID) REFERENCES Lists(id) ON DELETE CASCADE
)
INSERT INTO Lists (name)
VALUES("TEST1")
INSERT INTO Tasks(txt,listID)
VALUES("test1",1)
INSERT INTO Tasks(txt,listID)
VALUES("test2",1)
DELETE FROM Lists
WHERE id = 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|