ON DELETE CASCADE not working in SQLite

こ雲淡風輕ζ 提交于 2020-01-22 00:56:04

问题


In SQLite for iOS (3.7.7) I am running these queries:

PRAGMA foreign_keys = ON;

create table venue(id integer primary key not null, name text not null);

create table event(id integer primary key not null, name text not null, 
venue_id integer references venue(id) on delete cascade);

But when I delete a venue, the children events are not deleted. Any ideas?


回答1:


I followed what Catcall said and it worked for me: setting foreign_keys by running

stmt.execute("PRAGMA foreign_keys = ON");

each time I establish a connection to the database.




回答2:


The problem seems to be the usage of multiple handles in different threads although synchronized. Since sqlite included in iOS is new enough to allow one handle to be used across threads as long as they are properly synchronized, using one single handle instead of several should make this a no-problem. But I would be interested in getting to know how and if someone else solves this problem.



来源:https://stackoverflow.com/questions/7985645/on-delete-cascade-not-working-in-sqlite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!