0

when I try to insert values into my FKs in the DB Browser for SQLite I get the constraints error, but when I run the seeders with knex (npm package) it pass over the FK constraints and it inserts when it should return an error.

0

I had before my knexfile.js like this:

    var knex = require('knex')({
    dialect: 'sqlite3',
    connection: {
      filename: './database'
    },
    useNullAsDefault: true
  });

It was needed to activate here the PRAGMA for foreign_keys. To do it change it to:

    var knex = require('knex')({
    dialect: 'sqlite3',
    connection: {
      filename: './database'
    },
    pool: {
      afterCreate: function (conn, cb) {
        conn.run('PRAGMA foreign_keys = ON', cb)
      }
    },
    useNullAsDefault: true
  });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.