Darren rogers
Darren rogers

Reputation: 627

"no commandline connection parameters passed" Knex error

I am attempting to run a knexfile migration using the command

knex migrate:latest

and recieve the following error

/Users/<MYUSERNAME>/.npm-global/lib/node_modules/knex/bin/utils/cli-config-utils.js:8
    throw new Error(
    ^

Error: No default configuration file '/Users/<MYUSERNAME>/Desktop/Zipline/ed-tester/knexfile.js' found and no commandline connection parameters passed
    at mkConfigObj (/Users/<MYUSERNAME>/.npm-global/lib/node_modules/knex/bin/utils/cli-config-utils.js:8:11)

my knexfile.js

module.exports = {

  development: {
    client: 'postgresql',
    connection: {
      database: process.env.DB_NAME || 'db',
      user: process.env.DB_USERNAME,
      password: process.env.DB_PASSWORD,
      host: process.env.DB_HOSTNAME,
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations'
    }
  }
};

and my .env

DB_USERNAME=postgres
DB_HOSTNAME=localhost
DB_NAME=db
DB_PASSWORD=
DB_SSL=false

Can someone please explain what is wrong and how to fix.

Upvotes: 2

Views: 7795

Answers (3)

Vighnesh Kulkarni
Vighnesh Kulkarni

Reputation: 1019

You need to add --knexfile commandline parameter along with the path to the knexfile.

Example:- npx knex migrate:latest --knexfile ./db/knexfile.js

Note:- The path to the knexfile will be relative to where you are executing the command from.

Upvotes: 3

Benjamin Crouzier
Benjamin Crouzier

Reputation: 41905

I had the same error. My issue was the following:

I have a knexfile.js looking like this:

require('dotenv').config();
const { DB_USERNAME, DB_PASSWORD, APP_ENV } = process.env;
module.exports = {

  development: {
    // ...
  },

  staging: {
    // ...
  },

  production: {
    // ...
  },

}[APP_ENV];

And I was passing production-4 as the APP_ENV (it doesn't exist in my config). Passing an env that exists (production), or adding production-4 in my list of configs solves the issue.

Make sure knex gets a correct config (with client, connection, pool, migration...)

Upvotes: 1

Fazal Rasel
Fazal Rasel

Reputation: 4526

try by running following command- knex migrate:latest --env development

Upvotes: 2

Related Questions