【问题标题】:Specified 'sqlite3' for database adapter, but the gem is not loaded when running searchkick reindex?为数据库适配器指定了“sqlite3”,但运行 searchkick reindex 时未加载 gem?
【发布时间】:2018-06-18 05:52:14
【问题描述】:

首先我根据环境分离了数据库

group :production do 
  gem 'pg'
end


group :development, :test do
  gem 'byebug'
  gem 'sqlite3'
  gem 'rspec-rails'
end

添加几条记录后。我在生产环境中运行了以下重新索引命令。

bundle exec rake searchkick:reindex CLASS=Book

但它给出了以下错误

rake aborted!
Gem::LoadError: Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its v                                                   ersion is at the minimum required by ActiveRecord).
/book/shared/bundle/ruby/2.4.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/connection_specification.                                                   rb:176:in `rescue in spec'
/book/shared/bundle/ruby/2.4.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/connection_specification.                                                   rb:173:in `spec'
/book/shared/bundle/ruby/2.4.0/gems/activerecord-5.0.6/lib/active_record/connection_handling.rb:53:in `establish_conne                                                   ction'
/book/shared/bundle/ruby/2.4.0/gems/activerecord-5.0.6/lib/active_record/railtie.rb:125:in `block (2 levels) in <class                                                   :Railtie>'

Caused by:
Gem::LoadError: sqlite3 is not part of the bundle. Add it to your Gemfile.
/home/deploy/.rvm/gems/ruby-2.4.2/gems/bundler-1.16.0/lib/bundler/rubygems_integration.rb:404:in `block (2 levels) in replace_gem'
/book/shared/bundle/ruby/2.4.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/sqlite3_adapter.rb:7:in `                                                   <top (required)>'

尽管 pg 已设置为生产环境,但我感谢任何关于它为何搜索 sql 的帮助?

更新:

好的,我通过在 Rails 控制台生产中执行 Book.reindex 解决了这个问题,但我仍然想知道为什么

bundle exec rake searchkick:reindex CLASS=Book

因上述错误而失败?它在一开始就起作用了。在进行了一些升级(例如添加 aws-sdk)之后,它开始显示错误。 aws-sdk 会破坏它吗?

【问题讨论】:

    标签: ruby-on-rails ruby elasticsearch rake searchkick


    【解决方案1】:

    您可以尝试在生产组添加gem 'rails_12factor'

    宝石文件

     group :production do 
        gem 'pg'
        gem 'rails_12factor'
     end
    

    然后

    bundle install
    bundle update 
    

    然后推送到生产环境并测试它

    希望能帮到你

    【讨论】:

    • 好的,请看上面的更新。我解决了直接在控制台中运行 Book.reindex 的问题,但仍然想知道为什么 rake 命令因 sqlite 丢失错误而中断。
    • 我想减少用于生产的宝石数量。你能说出 gem 的具体作用以及它是如何解决问题的吗?
    猜你喜欢
    • 1970-01-01
    • 2014-08-11
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 2015-01-13
    相关资源
    最近更新 更多