【问题标题】:Heroku Deployment Error - Requiring ActiveRecordHeroku 部署错误 - 需要 ActiveRecord
【发布时间】:2017-05-29 21:31:58
【问题描述】:

这是我第一次尝试将后端 Rails 应用程序部署到 Heroku,我发现 ActiveRecord 存在问题。奇怪的是,我的应用程序中根本没有使用 ActiveRecord。它不在我的 Gemfile 中,而且我没有使用数据库。但是,当我部署到 Heroku 时,我在日志中看到了这条消息:

2017-05-29T21:07:47.824117+00:00 heroku[web.1]: Starting process with command `bundle exec rails server`
2017-05-29T21:07:52.180887+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/connection_specification.rb:176:in `rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)```

This leads to a long list of errors and warnings about ActiveRecord, culminating in `2017-05-29T21:10:40.107538+00:00 heroku[web.1]: State changed from starting to crashed`

followed by `2017-05-29T21:10:40.089176+00:00 heroku[web.1]: Process exited with status 1`.

After this first failure, the subsequent logs all read:

```2017-05-29T21:10:39.968550+00:00 app[web.1]:     from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `tap'
2017-05-29T21:10:39.968551+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `server'
2017-05-29T21:10:39.968551+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
2017-05-29T21:10:39.968552+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
2017-05-29T21:10:39.968553+00:00 app[web.1]:    from bin/rails:9:in `require'
2017-05-29T21:10:39.968553+00:00 app[web.1]:    from bin/rails:9:in `<main>'
2017-05-29T21:10:39.983313+00:00 app[web.1]: => Booting Puma
2017-05-29T21:10:39.983318+00:00 app[web.1]: => Rails 5.0.2 application starting in production on http://0.0.0.0:11396
2017-05-29T21:10:39.983319+00:00 app[web.1]: => Run `rails server -h` for more startup options
2017-05-29T21:10:39.983320+00:00 app[web.1]: Exiting
2017-05-29T21:10:40.089176+00:00 heroku[web.1]: Process exited with status 1

但是,我无法安装 sqlite3 gem,因为 Heroku 不支持它。有谁知道如何删除对 ActiveRecord 的要求,或者是否是其他原因导致此错误?

【问题讨论】:

    标签: ruby-on-rails heroku activerecord deployment


    【解决方案1】:

    在您的 Gemfile 中将 gem 'sqlite3' 替换为 gem 'pg'。尽管您可能不需要数据库,但 Heroku 在 Rails 堆栈中提供了一个。 Rails 本身与 ActiveRecord 一起打包,即使您不使用它。

    用 pg 替换 sqlite3 应该可以帮助您解决这个问题。

    【讨论】:

    • 谢谢,这成功了!我还必须更改 database.yml 文件以考虑 postgresql
    猜你喜欢
    • 2021-11-18
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 2017-12-01
    • 1970-01-01
    相关资源
    最近更新 更多