IgorOK
IgorOK

Reputation: 1662

Foreign keys in android 2.2 and higher

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:

  1. Why are foreign keys disabled by default?
  2. Have you better solution to enable foreign keys?

Thanks!

Upvotes: 0

Views: 128

Answers (1)

Jens
Jens

Reputation: 17077

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 PRAGMA is the correct way to enable foreign key support.

Upvotes: 3

Related Questions