node.js - 无法在 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
解决方案
正如我在评论中与 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"
}
}
推荐阅读
- android - 在带有 RecyclerViews 和 Fragments 的应用程序中使用 Volley - 烘焙应用程序
- android - Oreo 更新后出现 INSTALL_FAILED_NO_MATCHING_ABIS 错误
- java - 如何使用 Spring 数据快速添加/删除多对多关系中的对象
- typescript - 修改了数组的对象属性,但在页面上没有更改
- timeout - HP Load Runner 12.55 中的步骤下载超时
- javascript - 活动课程未重置
- python - 顺序模型中的pytorch跳过连接
- r - 将经纬网添加到 R 中的投影地图
- spring - 创建名为“userServiceImpl”的 bean 时出错:通过字段“userDAO”表达的不满足依赖关系;
- java - GSON 使用成员 ArrayList 反序列化对象