Node-sqlite3: Is foreign key support enabled?

Created on 18 Oct 2017  路  3Comments  路  Source: mapbox/node-sqlite3

Hello there,

I've just started with node-sqlite3 (first time with sql as well) and I've been having some errors that lead me thinking about foreign key support, and then I found the following post on the sqlite foreign key support page, and I couldn't find any information regarding it here.

So, is there anything that I need to do regarding the foreign key support?

In order to use foreign key constraints in SQLite, the library must be compiled with neither SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER defined. If SQLITE_OMIT_TRIGGER is defined but SQLITE_OMIT_FOREIGN_KEY is not, then SQLite behaves as it did prior to version 3.6.19 (2009-10-14) - foreign key definitions are parsed and may be queried using PRAGMA foreign_key_list, but foreign key constraints are not enforced. 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 to specify a foreign key definition is a syntax error).

Most helpful comment

It seems like it's not enabled by default, but you can enable it by running:

db.get("PRAGMA foreign_keys = ON")

All 3 comments

It seems like it's not enabled by default, but you can enable it by running:

db.get("PRAGMA foreign_keys = ON")

Thanks! :)

@literallylara @mnemanja where i put this option in my code or what object of knex has this function get? I tried but don't get success.

Was this page helpful?
0 / 5 - 0 ratings