AJcodez
AJcodez

Reputation: 34236

Knex migration not working, whats wrong?

I can't seem to migrate the database with knex. In the up command, it fails.

knex.migrate.latest({}).finally(function () {
  knex.destroy()
})

I get an error.

Possibly unhandled TypeError: undefined is not a function
    at SchemaBuilder_PG.Target.then (cwd/node_modules/knex/lib/interface.js:25:10)
    at SchemaBuilder_PG.Target.(anonymous function) [as bind] (cwd/node_modules/knex/lib/interface.js:71:21)
    at Migrator_PG.<anonymous> (cwd/node_modules/knex/lib/migrate/index.js:93:6)
    at Migrator_PG.<anonymous> (cwd/node_modules/knex/lib/migrate/index.js:138:15)
    at Migrator_PG.Migrator._migrationData (cwd/node_modules/knex/lib/migrate/index.js:154:10)
    at Migrator_PG.<anonymous> (cwd/node_modules/knex/lib/migrate/index.js:22:15)
From previous event:
    at Function.Promise$All [as all] (cwd/node_modules/knex/node_modules/bluebird/js/main/promise.js:198:12)
    at Migrator_PG.Migrator._migrationData (cwd/node_modules/knex/lib/migrate/index.js:152:18)
    at Migrator_PG.<anonymous> (cwd/node_modules/knex/lib/migrate/index.js:22:15)

I swear it was working yesterday. I tried dropping and recreating the database. No luck. What's wrong? How can I fix this?

Nothing seems evident digging in knex source.

Upvotes: 4

Views: 3650

Answers (1)

AJcodez
AJcodez

Reputation: 34236

Nevermind, was stupid. Trying to use an environment variable in the configuration that wasn't set.

var knex = require('knex')

var config = {
  client: 'pg',
  connection: process.env.DATABASE_URL,
}

module.exports = knex(config)

Working now.

Upvotes: 6

Related Questions