question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to enable foreign keys? PRAGMA statement?

See original GitHub issue

Hi, Ive noticed my ON CASCADE DELETE doesnt work, is it because of foreign keys being turned off on android by default? If so, how can turn them on?

Naively putting them at the top of Foo.sq file PRAGMA foreign_keys = ON; does not compile, and PRAGMA foreign_keys = 1; does not work

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

27reactions
ursusursuscommented, Feb 27, 2019

For future readers

val driver = AndroidSqliteDriver(
    schema = Database.Schema,
    context = context,
    name = "mydb",
    callback = object : AndroidSqliteDriver.Callback(Database.Schema) {
        override fun onOpen(db: SupportSQLiteDatabase) {
            db.execSQL("PRAGMA foreign_keys=ON;");
        }
    })
3reactions
vanniktechcommented, Jun 24, 2020

I’m doing driver.execute(null, "PRAGMA foreign_keys=ON", 0)

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQLite Foreign Key Support
The application can also use a PRAGMA foreign_keys statement to determine if foreign keys are currently enabled. The following command-line ...
Read more >
How do I activate foreign keys in C, using sqlite?
The PRAGMA foreign_keys command is a no-op in this configuration. If OMIT_FOREIGN_KEY is defined, then foreign key definitions cannot even be parsed (attempting ......
Read more >
SQLite Foreign Key: Enforce Relationships Between Tables
If the SQLite library is compiled with foreign key constraint support, the application can use the PRAGMA foreign_keys command to enable or disable...
Read more >
SQLite: Foreign Keys
You can not use the ALTER TABLE statement to add a foreign key in SQLite. Instead you will need to rename the table,...
Read more >
Foreign Key constraints
You can use the spatialite-gui tools as well, if you wish. Step #2: spatialite> PRAGMA foreign_keys;. 1. By default any SQLite connection starts...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found