首页 > 解决方案 > 无法在 Heroku 上运行迁移 Postgres

问题描述

好吧,当我输入 heroku bash 并尝试运行npx typeorm migration:run它时,它只会给我一个错误: 在此处输入图像描述

奇怪的是,当 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:如果需要,这是项目的repo:https ://github.com/joaocasarin/gittin

标签: node.jspostgresqlherokutypeorm

解决方案


正如我在评论中与 Carlo 讨论的那样,我必须在 中添加ssl属性ormconfig.js,但不仅仅是在环境为production. 所以根据这个,我不得不把{ rejectUnauthorized: 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"
    }
}

推荐阅读