KennethCruz
KennethCruz

Reputation: 31

Failed to resolve config file, knex cannot determine where to generate migrations

I’m trying to migrate and seed in a certain directory(database dir). But when I run:

npx knex migrate:make testing_table

it shows:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:124:11)

Directory

What I've done is that I’ve moved the knexfile.js outside the database directory and into the main directory. It works and migrates, but it creates another migration folder in the main rather than creating a table in the current migration folder.

Here is the code:

connection:

const config = require('../db/knexfile')
const env = process.env.NODE_ENV || 'development'
const connection = knex(config[env])

module.exports = connection

knex file:


module.exports = {
  development: {
    client: 'sqlite3',
    connection: {
      filename: './dev.sqlite3'
    },
    useNullAsDefault: true,
    // Getting SQlite to honour contraints
    pool: {
      afterCreate: (conn, cb) =>
        conn.run('PRAGMA foreign_keys = ON', cb)
    }
  },

  test: {
    client: 'sqlite3',
    connection: {
      filename: ':memory:'
    },
    useNullAsDefault: true,
    seeds: {
      directory: path.join(__dirname, 'tests/seeds')
    },
    migrations: {
      directory: path.join(__dirname, 'migrations')
    }
  },

  production: {
    client: 'sqlite3',
    connection: process.env.DATABASE_URL,
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      directory: path.join(__dirname, './server/db/migrations')
    },
    seeds: {
      directory: path.join(__dirname, './seeds')
    }
  }
}

Upvotes: 3

Views: 7380

Answers (2)

Prateek Verma
Prateek Verma

Reputation: 17

This worked for me :npx knex migrate:make testing_table --migrations-directory folder-name

Upvotes: 0

Vighnesh Kulkarni
Vighnesh Kulkarni

Reputation: 1019

if you have moved the knexfile into Main Folder(as you've mentioned in the folder structure), you'll have to change the path of migrations directory as follows:-

test: {
client: 'sqlite3',
connection: {
  filename: ':memory:'
},
useNullAsDefault: true,
seeds: {
  directory: path.join(__dirname, 'tests/seeds')
},
migrations: {
  directory: path.join(__dirname, './Database/Migrations') //--Changed this line
}},   

Upvotes: 2

Related Questions