In android 2.2 and higher SQLite supports foreign keys but they are disabled by default.
In my application I use database.execSQL(“PRAGMA foreign_keys=ON”); every time after open database.
I have two questions:
- Why are foreign keys disabled by default?
- Have you better solution to enable foreign keys?
Thanks!
Foreign keys are disabled by default in stock SQLite also (for backwards compatibility) – I think it even says so in the SQLite FK documentation. So Android is simply not messing with the default behaviour.
The
PRAGMAis the correct way to enable foreign key support.