首先,我根据环境分离了数据库
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)>'
我很感激任何关于为什么它正在搜索 sql 的帮助,尽管 pg 已设置为生产?
更新:
好的,我通过在 rails 控制台生产中执行 Book.reindex 解决了这个问题,但我仍然想知道为什么
bundle exec rake searchkick:reindex CLASS=Book
失败并出现上述错误?它一开始就起作用了。在进行一些升级(例如添加aws-sdk(后,它开始显示错误。aws-sdk 会破坏它吗?
您可以尝试在生产组上添加gem 'rails_12factor'
宝石文件
group :production do
gem 'pg'
gem 'rails_12factor'
end
然后
bundle install
bundle update
然后推送到生产环境并进行测试
希望对您有所帮助