无法在 Heroku 上运行迁移 Postgres

时间:2021-07-16 13:24:01

标签: node.js postgresql heroku typeorm

好吧,当我输入 heroku bash 并尝试运行 npx typeorm migration:run 时,它只会向我抛出一个错误: enter image description here

奇怪的是,当 DATABASE 在本地主机上时,它在本地工作,就像这样在 .env 文件中: DATABASE_URL=postgres://postgres:docker@localhost:5432/gittin

这是我的ormconfig.js

module.exports = {
    "type": "postgres",
    "url": process.env.DATABASE_URL,
    "entities": ["dist/entities/*.js"],
    "cli": {
        "migrationsDir": "src/database/migrations",
        "entitiesDir": "src/entities"
    }
}

是的,我在应用中添加了 heroku postgres 插件。

PS:如果需要,这是项目的仓库:https://github.com/joaocasarin/gittin

1 个答案:

答案 0 :(得分:0)

当我在评论中与 Carlo 讨论时,我必须在 ssl 中添加 ormconfig.js 属性,但不仅在环境为 production 时将其设置为 true。所以根据this,我必须在生产模式时输入{ rejectUnauthorized: false },否则就为false。

所以 ormconfig.js 现在是这样的:

module.exports = {
    "type": "postgres",
    "ssl": process.env.NODE_ENV === 'production' ? { rejectUnauthorized: false } : false,
    "url": process.env.DATABASE_URL,
    "entities": ["dist/entities/*.js"],
    "cli": {
        "migrationsDir": "src/database/migrations",
        "entitiesDir": "src/entities"
    }
}