0
votes

I am making small Sinatra app and trying to put it on Heroku server.

when I do Heroku run rake db:migrate, Heroku is giving error "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)." .

While I have a sqlite3 gem in development group in my gem file.

source 'http://rubygems.org'
ruby '2.3.1'

gem 'sinatra'
gem 'activerecord', :require => 'active_record'
gem 'sinatra-activerecord', :require => 'sinatra/activerecord'
gem 'sqlite3', :group => :development
gem 'rake'
gem 'require_all'
gem 'thin'
gem 'shotgun', :group => :development
gem 'pry'
gem 'bcrypt'
gem "tux"
gem 'rack-flash3'

group :test do
  gem 'rspec'
  gem 'capybara'
  gem 'rack-test'
  gem 'database_cleaner', git: 'https://github.com/bmabey/database_cleaner.git'
end

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

Also, please see below environment file

require 'bundler/setup'
require 'rack-flash'

Bundler.require

configure :development do
  ENV['SINATRA_ENV'] ||= "development"

  ActiveRecord::Base.establish_connection(
     :adapter => "sqlite3",
     :database => "db/#{ENV['SINATRA_ENV']}.sqlite"
   )
end

configure :production do
  db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/mydb')

  ActiveRecord::Base.establish_connection(
     :adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
     :host     => db.host,
     :username => db.user,
     :password => db.password,
     :database => db.path[1..-1],
     :encoding => 'utf8'
  )
end

require_all 'app'

I also did "bundle install --without production" and pushed everything on Github. Does anyone have any possible solution?

Thanks a lot!

1
I think you need to remove group => development from the sqlite3 gem so it will load in your production environment. - moveson
Wouldn't it be simpler (and more reliable in the long run) to install PostgreSQL in your dev environment so that you'll be developing, testing, and deploying with the same stack? - mu is too short

1 Answers

0
votes

The error comes from having group => development in the gem 'sqlite3' line of your gemfile.

What you need to understand is what environment your Heroku server is using.

To check, try running heroku run console -a your-app-name from the command line (you need the Heroku CLI installed).

Now run Sinatra::Base.development? or Sinatra::Base.production?

The results of running these commands should help you understand why including group => development is causing rake db:migrate to fail on Heroku and not your local dev environment.