【问题标题】:Database issues with Heroku deploymentHeroku 部署的数据库问题
【发布时间】:2011-11-06 22:22:00
【问题描述】:

我有一个基本应用程序,我正在尝试将其部署到 Heroku。我可以用 git 将它推送到 Heroku,它会显示默认的 Rails 欢迎页面,但是当我尝试访问任何子页面时,(当我使用 rails server 在本地服务器上部署时工作的页面)我收到“出现问题”消息.

我调出日志,收到来自服务器的 500 条响应和大量 ActiveRecord::ConnectionNotEstablished 消息,这似乎是连接到数据库的问题。

此外,当我尝试运行 heroku rake db:migrate 时,我收到以下错误

rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adap
ter` (pg is not part of the bundle. Add it to Gemfile.)

Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)

根据上面的建议,在运行gem install pgbundle install 之后,我确实将gem 'pg' 添加到了Gemfile。另外,我尝试了gem install activerecord-postgresql-adapter(在 Windows 上)并得到了

ERROR:  Could not find a valid gem 'activerecord-postgresql-adapter' (>= 0) in a
ny repository
ERROR:  Possible alternatives: activerecord-jdbcpostgresql-adapter, activerecord
-postgis-adapter, activerecord-jdbcmssql-adapter, activerecord-jdbcmysql-adapter
, activerecord-postgresql-cursors

根据我正在阅读的书的建议,我运行了heroku db:push 并且它没有错误地竞争,但是它并没有解决应用程序推送到 Heroku 后页面不呈现的问题。

更新:我已尝试按照建议安装 activerecord-jdbcpostgresql-adapter 作为可能的替代方案。我用

更新了 Gemfile
group :production, :staging do
  gem 'pg'
end

和database.yml文件

production:
  adapter: jdbcpostgresql

当我 heroku rake db:migrate 时,它仍然给我消息告诉我安装 postgresql 适配器

【问题讨论】:

    标签: ruby-on-rails deployment heroku


    【解决方案1】:

    如果heroku rake db:migrate 运行没有错误,那么您的数据库连接信息是正确的。很可能还有另一个错误导致页面无法正确呈现。如果您在发出请求时跟踪您的 heroku 日志,您是否仍然收到相同的数据库错误?我怀疑您会发现这是一个需要修复的不同错误。

    【讨论】:

    • 你的适配器需要是'postgresql',而不是'jdbcpostgresql';后者用于 JRuby 部署,Heroku 不运行。尝试按照您的方式安装 pg gem 并使用adapter: postgresql
    猜你喜欢
    • 2021-10-19
    • 2011-07-19
    • 1970-01-01
    • 2015-06-05
    • 2016-05-11
    • 2017-05-04
    • 2013-06-17
    • 2023-04-10
    • 2021-02-28
    相关资源
    最近更新 更多