【发布时间】:2019-07-15 11:57:28
【问题描述】:
我有一个 Express API 部署到 Heroku,但是当我尝试运行迁移时,它会抛出以下错误:
heroku 运行 knex migrate:latest 运行 knex migrate:latest on ⬢ bookmarks-node-api... up, run.9925 (免费) 使用环境: 生产错误:连接 ECONNREFUSED 127.0.0.1:5432 在 TCPConnectWrap.afterConnect [as oncomplete] (net.js:1117:14)
在我的knexfile.js 中,我有:
production: {
client: 'postgresql',
connection: {
database: process.env.DATABASE_URL
},
pool: {
min: 2,
max: 10
},
migrations: {
directory: './database/migrations'
}
}
我还尝试将迁移目录分配给tableName: 'knex_migrations',这会引发错误:
heroku 运行 knex migrate:latest 运行 knex migrate:latest on ⬢ bookmarks-node-api... up, run.7739 (免费) 使用环境: 生产错误:ENOENT:没有这样的文件或目录,scandir '/app/迁移'
这是在 Heroku 中设置的配置:
-node-api git:(master) heroku pg:info
=== DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 10.7
Created: 2019-02-21 12:58 UTC
Data Size: 7.6 MB
Tables: 0
Rows: 0/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
我认为问题在于,出于某种原因,它正在查看数据库的 localhost,就好像环境被读取为 development 尽管跟踪显示 Using environment: production。
【问题讨论】:
标签: postgresql express heroku knex.js