heroku rails使用Elasticsearch Gem :: LoadError sqlite3问题

时间:2016-12-30 05:26:02

标签: ruby-on-rails heroku

rails app使用gem 'searchkick'

运行:

heroku addons:open bonsai
heroku config:set ELASTICSEARCH_URL=`heroku config:get BONSAI_URL`
heroku run rake searchkick:reindex CLASS=Product

发生问题

rake aborted!
Gem::LoadError: 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).

的Gemfile:

source 'https://rubygems.org'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
group :development, :test do
  gem 'byebug', platform: :mri
end

group :development do
  gem 'web-console'
  gem 'listen', '~> 3.0.5'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.7'
gem 'haml', '~> 4.0', '>= 4.0.7'
gem 'devise', '~> 4.2'
gem 'simple_form', '~> 3.3', '>= 3.3.1'
gem 'paperclip', '~> 5.1'
gem 'searchkick', '~> 1.4'
gem 'will_paginate', '~> 3.1', '>= 3.1.5'
gem 'will_paginate-bootstrap', '~> 1.0', '>= 1.0.1'

group :development do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
end

database.yml中:

    default: &default
      adapter: sqlite3
      pool: 5
      timeout: 5000

    development:
      <<: *default
      database: db/development.sqlite3
    test:
      <<: *default
      database: db/test.sqlite3

    production:
      <<: *default
      database: db/production.sqlite3

模型:

article.rb

class Article < ApplicationRecord

  searchkick
  has_many :comments, dependent: :destroy
  belongs_to :user
  belongs_to :node
  has_attached_file :article_img, styles: { index_img: "300x300>", show_img: "100x100>" }, default_url: "/images/:style/missing.png"
  validates_attachment_content_type :article_img, content_type: /\Aimage\/.*\z/
end
发生数据库sqlite3应该怎么做?

1 个答案:

答案 0 :(得分:0)

您正在使用sqlite3适配器用于生产环境,但在Gemfile中您提到要在生产中使用pg数据库,而仅在开发中使用sqlite。因此,您需要根据使用情况修复Gemfiledatabase.yml