簡體   English   中英

將我的 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 push 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 的全功能配置。 我真的會將幾乎所有內容保留為默認值,僅需要時調整數據庫 更喜歡在本地使用ENV["DATABASE_URL"]以及設置密碼和用戶名等內容,因為它避免了開發者戰爭。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM