foreign key constraint ON DELETE CASCADE not working in sqlite database on android foreign key constraint ON DELETE CASCADE not working in sqlite database on android android android

foreign key constraint ON DELETE CASCADE not working in sqlite database on android


Cascading delete isn't supported until Sqlite version 3.6.19, which is first included on Android 2.2.

Fortunately there is an alternative.

You can execute another query like this below your create table query:

db.execSQL("CREATE TRIGGER delete_days_with track BEFORE DELETE ON track "       +  "FOR EACH ROW BEGIN"       +         " DELETE FROM days WHERE track.day_id = days.day_id "       +  "END;");

Note that delete_days_with_track is just a name descriptive of what the trigger does, and this is just the pattern I use; I believe you could name it anything you wish.


According to the SQLite Documentation support for Foreign Keys was not added until 3.6.19.

Using 3.5.9 you'll have to do your cascade deletions in some other manner.