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



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

我不得不从SQLite3切换到PostgreSQL,这样我就可以在Heroku上部署。当我在本地运行时,一切正常。在我git推送heroku大师之后发生了一个错误。它开始部署,我得到这个:

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

后跟堆栈跟踪。

我想我一路上搞砸了一些东西。我只是不知道它在期待什么,或者我应该在哪里寻找。我的数据库.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 的功能齐全的配置。我真的会把几乎所有内容都保留为默认值,只在需要时调整数据库。更喜欢在本地使用ENV["DATABASE_URL"]来设置密码和用户名等内容,因为它可以避免开发人员战争。

最新更新