【问题标题】:I cannot connect Postgres DB with Strapi on Heroku我无法在 Heroku 上将 Postgres DB 与 Strapi 连接起来
【发布时间】:2020-06-11 13:54:24
【问题描述】:

我尝试在 Heroku 上设置 Strapi + PostgresDB。

我按照这个手册一步一步来https://strapi.io/documentation/3.0.0-beta.x/deployment/heroku.html

当我部署到 Heroku 时,我得到:应用程序错误

heroku logs --tail 显示

npm ERR! my-host-cms@0.1.0 start: `strapi start`
2020-06-09T14:54:44.272624+00:00 app[web.1]: npm ERR! Exit status 1
2020-06-09T14:54:44.272950+00:00 app[web.1]: npm ERR!
2020-06-09T14:54:44.273144+00:00 app[web.1]: npm ERR! Failed at the my-host-cms@0.1.0 start script.
2020-06-09T14:54:44.273335+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-06-09T14:54:44.289977+00:00 app[web.1]:
2020-06-09T14:54:44.290269+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-06-09T14:54:44.290445+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-06-09T14_54_44_278Z-debug.log
2020-06-09T14:54:44.353188+00:00 heroku[web.1]: Process exited with status 1
2020-06-09T14:54:44.386798+00:00 heroku[web.1]: State changed from starting to crashed
2020-06-09T14:54:44.388614+00:00 heroku[web.1]: State changed from crashed to starting
2020-06-09T14:55:01.903657+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-09T14:55:05.469266+00:00 app[web.1]:
2020-06-09T14:55:05.469295+00:00 app[web.1]: > my-host-cms@0.1.0 start /app
2020-06-09T14:55:05.469296+00:00 app[web.1]: > strapi start
2020-06-09T14:55:05.469296+00:00 app[web.1]:
2020-06-09T14:55:08.015032+00:00 app[web.1]: [2020-06-09T14:55:08.013Z] error The client `sqlite3` is not installed.
2020-06-09T14:55:08.015961+00:00 app[web.1]: [2020-06-09T14:55:08.015Z] error You can install it with `$ npm install sqlite3 --save`.

2020-06-09T14:55:09.623864+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=my-host.herokuapp.com request_id=eea79361-593f-413e-89e2-d99d0153ddf3 fwd="37.57.145.70" dyno= connect= service= status=503 bytes= protocol=https
2020-06-09T15:01:07.901262+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=my-host.herokuapp.com request_id=ce0353b0-5e45-422d-af43-f96614c8151d fwd="37.57.145.70" dyno= connect= service= status=503 bytes= protocol=https

我看到它询问 sqlite3 但我有它 package.json

该项目是用--quickstart 发起的,但我已经创建了./config/environments/production/database.json

【问题讨论】:

    标签: postgresql heroku strapi


    【解决方案1】:

    如果您使用 --quickstart 标志安装了 Strapi,那么默认情况下它会为您提供 SQLite 数据库。

    • 由于您为 postpres 加载了 db 配置,请确保您安装了 pg。
    • 如果你不在本地使用它,你可以 npm/yarn 从你的 package.json 中删除 sqlite3,即你已经安装了 postgres 并且服务正在运行。
    • 删除缓存文件夹,然后npm run build
    • 现在推送到heroku并打开。

    仅供参考。建议您使用 database.js 而不是 database.json 例如。

    module.exports = ({ env }) => ({
      defaultConnection: 'default',
      connections: {
        default: {
          connector: 'bookshelf',
          settings: {
            client: 'postgres',
            host: env('DATABASE_HOST'),
            port: env.int('DATABASE_PORT'),
            database: env('DATABASE_NAME'),
            username: env('DATABASE_USERNAME'),
            password: env('DATABASE_PASSWORD'),
            ssl: env.bool('DATABASE_SSL'),
          },
          options: {}
        },
      },
    });
    

    确保在 Heroku 中配置了 postgres 插件。 检查您在 heroku 中的配置变量是否正确。 还要确保 ./config/database.js 或 ./config/database.json 也已更正以使用正确的数据库。

    【讨论】:

      猜你喜欢
      • 2020-09-16
      • 2019-07-15
      • 2021-09-03
      • 2019-02-12
      • 2021-11-01
      • 2017-09-24
      • 2018-07-21
      • 2018-10-17
      • 1970-01-01
      相关资源
      最近更新 更多