Knex迁移不起作用,出了什么问题?

4

我似乎无法使用knex迁移数据库。在up命令中,它会失败。

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

我遇到了一个错误。
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)

我发誓昨天它还能用。我尝试删除并重新创建数据库,但没有成功。怎么回事?我该如何解决?

研究Knex源代码时似乎没有发现任何问题。

1个回答

6

没事了,是我太蠢了。我试图在配置中使用一个未设置的环境变量。

var knex = require('knex')

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

module.exports = knex(config)

正在工作中。


1
谢谢,我刚遇到了类似的问题。最好让“initialize”函数捕获它。 - Rhys van der Waerden

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接