我无法在Heroku上将Postgres DB与Strapi连接

时间:2020-06-11 13:54:24

标签: postgresql heroku strapi

我尝试在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

1 个答案:

答案 0 :(得分:0)

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

  • 自从为postpres加载数据库配置后,请确保已安装pg。
  • 如果您未在本地使用它,则可以npm / yarn从package.json中删除sqlite3,即您已经安装了postgres并且该服务正在运行。
  • 删除您的缓存文件夹,然后删除npm run build
  • 现在推到heroku并打开。
菲。建议您在database.json上使用database.js 例如。

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也已更正为使用正确的数据库。