Created
November 26, 2019 00:58
-
-
Save jasheloper/60dfd7b5f89d8e8b8e9e614482a61ba0 to your computer and use it in GitHub Desktop.
Foreign Key Setup - In Knex, foreign key restrictions don’t automatically work. Whenever using foreign keys in your schema, add the following code to your knexfile. This will prevent users from entering bad data into a foreign key column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
development: { | |
client: 'sqlite3', | |
useNullAsDefault: true, | |
connection: { | |
filename: './data/database.db3', | |
}, | |
// needed when using foreign keys | |
pool: { | |
afterCreate: (conn, done) => { | |
// runs after a connection is made to the sqlite engine | |
conn.run('PRAGMA foreign_keys = ON', done); // turn on FK enforcement | |
}, | |
}, | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment