-2

I am using heroku in a rails blog. After being able to fix the gem file following many related answers here, and being able to push my blog to heroku the app is not working locally.

I have change 'sqlite3' for 'pg' in my production env and add 'sqilte3' only in development test, push my changes to git and after to heroku. So far it was working but when I try to run the rails server, is asking me for 'sqlite3' again.

Error:

rb:177:in rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Addgem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)

GEMFILE 

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'devise'

gem 'will_paginate', '~> 3.0.5'

gem 'cancancan'

gem "paperclip", "~> 5.0.0.beta1"

gem 'ratyrate'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  gem "sqlite3"

  gem 'rspec-rails', '~> 3.0'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :production do
  gem 'rails_12factor'
  gem 'pg'
end
DATABASE.YML

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

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

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3
I have followed the steps here >> http://railscasts.com/episodes/342-migrating-to-postgresql?view=asciicast >> and is working now. Note for beginners, if you are going to use rails and heroku start you application with pg to save time debugging this.
Chema Mora
  • 11
  • 7

3 Answers3

2

I know it's a very old question but i got the same issue yesterday, am using Ubuntu 16.04 Rails 5.1.6.

I tried every solution that i found on the web but nothing worked for me, so am writing what solved this issue for me so it can help someone who get into this issue.

Simply check what version of Sqlite3 gem you are using:

bundle show sqlite3

for me it was sqlite3-1.4.0

Now just downgrade to a older version of the sqlite3 gem Simply add gem 'sqlite3', '~> OLDER VERSION' in your gemfile replacing your current version of sqlite3

bundle install

That's it, it should work.

That dude
  • 379
  • 1
  • 4
  • 17
0

If you are using pg in production than... why sqlite3 confugration here

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

update it from pg configuration.

Heroku is not compatible with sqlite3, you should use pg

Pg config.

development:
  adapter: postgresql
  encoding: unicode
  database: blog_development
  pool: 5
  username: blog
  password:
Mukesh
  • 921
  • 10
  • 23
0

I would suggest removing the whole default section of your database.yml and just set everything for the rest:

development:
  adapter: sqlite3
  pool: 5
  timeout: 5000
  database: db/development.sqlite3

test:
  adapter: sqlite3
  pool: 5
  timeout: 5000
  database: db/test.sqlite3

production:
  adapter: postgresql
  encoding: unicode
  database: <project name>
  username: <%= ENV['USERNAME'] %>
  password: <%= ENV['PASSWORD'] %>
xyious
  • 1,065
  • 4
  • 13
  • 29
  • You'll have to export username and password in heroku and you'll have to replace project name with your project's name, or whatever database name you want to use. This way you'll keep your database the same in development so you'll be able to export the data and get it into the postgres db if you need to. – xyious Jun 07 '16 at 00:53