将我的 Rails 数据库切换到 Heroku 的 PostgreSQL,现在应用程序根本无法访问数据库

Switched my Rails database to PostgreSQL for Heroku, and now the app can't access the DB at all

我真的被这个难住了。我已经尝试了很多东西。

我必须从 SQLite3 切换到 PostgreSQL,这样我才能在 Heroku 上部署。当我在本地 运行 时一切正常。在我 git 推送 heroku master 之后发生了一个错误。它开始部署,我得到这个:

Rails couldn't infer whether you are using multiple databases from your database.yml and can't generate the tasks for the non-primary databases. If you'd like to use this feature, please simplify your ERB.

当我 运行 heroku rake 时也会发生这种情况,只是后面跟着这个:

rake aborted! Psych::BadAlias: Cannot load database configuration: Unknown alias: default

后跟堆栈跟踪。

我想我一路上搞砸了。我只是不知道它在期待什么,或者我应该看哪里。我的 database.yml 看起来像这样:

production: adapter: postgresql encoding: utf8 pool: 15 <<: *default url: *db url from heroku* timeout: 5000

非常感谢任何帮助。我对这一切都很陌生。我试过删除并重置数据库。我可以提供的最后一点证据是来自 Heroku 的日志:

heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ohmydog.herokuapp.com request_id=6217a180-f9ef-43da-8bb0-fc5d064e11fb fwd="185.232.22.206" dyno= connect= service= status=503 bytes= protocol=https

实际上你几乎不需要做任何配置就可以让 Postgres 在 Heroku 上工作,因为它通过 ENV["DATABASE_URL"] 提供了几乎整个配置,它自动与 database.yml.

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 15 } %>

development:
  <<: *default
  database: my_app_development

test:
  <<: *default
  database: my_app_test

production:
  <<: *default

这实际上是 Postgres.app 本地和 Heroku 的全功能配置。我真的会把几乎所有的东西都保留在默认值,只在需要时 tune the DB 。更喜欢在本地使用 ENV["DATABASE_URL"] 来设置密码和用户名之类的东西,因为它可以避免开发人员之间的战争。