G

Sqlite foreign keys "ON DELETE CASCADE" do not work

The support of foreign keys do not seem be effective, despite "PRAGMA foreign_key = 1" is set after the initialization. Some ideas: - http://p-s.co.nz/wordpress/foreign-key-support-in-sqlite-and-python/ - if twisted adbapi opens several threads, the pragma is set only for one of them - ... ?
G

Adrien 24/03/2014, 14:54

The reason seems to be twisted running the queries in different threads. One solution is to launch your query as an interaction and preceed it with the pragma setting. For example, replace: d = self.dbpool.runQuery("DELETE FROM profiles WHERE name = ?", (name, )) with: def delete(txn): txn.execute("PRAGMA foreign_keys = ON") txn.execute("DELETE FROM profiles WHERE name = ?", (name,)) return None d = self.dbpool.runInteraction(delete)

id

71

author

Adrien

created

24/03/2014, 12:25

updated

24/03/2014, 14:54

labels
Backend
type
bug
status
closed
priority
normal
milestone
0.7
severity
normal