0

I'm using the ActiveRecord class and was using "sqlite3" as the default. Then I wanted to deploy it on Heroku (which uses PostgreSQL). So I just added that in the Gemfile and installed the dependencies.

When I try to push to Heroku, it throws errors such as:

remote:        Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
remote:   
remote:        /tmp/build_12cfde1548d0f1ff19f95340a86aab63/vendor/ruby-2.0.0/bin/ruby extconf.rb
remote:        checking for sqlite3.h... no
remote:        sqlite3.h is missing. Try 'port install sqlite3 +universal',
remote:        'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
remote:        and check your shared library search path (the
remote:        location where your sqlite3 shared library is located).
remote:        *** extconf.rb failed ***

So then I tried removing the sqlite3 gem and I get this error from the application when I try to run it (I haven't tried deploying on Heroku yet):

Error:[rake --tasks] /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': 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). (Gem::LoadError)
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:50:in `establish_connection'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/base.rb:315:in `<module:ActiveRecord>'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/base.rb:26:in `<top (required)>'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:319:in `active_record_configured?'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:251:in `disconnect_database'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:97:in `preload'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:143:in `serve'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:131:in `block in run'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:125:in `loop'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:125:in `run'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application/boot.rb:18:in `<top (required)>'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'

I have run out of ideas and am very new to ruby or rails for that matter. Any help is appreciated!

 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.2'
 # 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' , '>= 4.0.3'
 # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
 gem 'turbolinks', '2.3.0'
 # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
 gem 'jbuilder', '2.2.3'
 # bundle exec rake doc:rails generates the API under doc/api.
 gem 'sdoc', ' 0.4.0', group: :doc

 # 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
 # Use sqlite3 as the database for Active Record
   #gem 'sqlite3'
   #gem 'activerecord'

   gem 'pg'
   gem 'rails_12factor', '>= 0.0.2'
   # Call 'byebug' anywhere in the code to stop execution and get a debugger console
   gem 'byebug', '>= 3.4.0'

   # 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
   #This is for use with Heroku
   gem 'pg'
   gem 'rails_12factor', '>= 0.0.2'
 end

And here's a look at my database.ml file:

# 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

Update 2:

I'm getting this error if I try to run the development (localhost) db on the web page:

Screenshot of webpage

When I add it to the development and test group, I still get these errors:

remote:        
remote:        Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
remote:        
remote:        /tmp/build_23334fae90f17ca215e6f12340967cbd/vendor/ruby-2.0.0/bin/ruby extconf.rb
remote:        checking for sqlite3.h... no
remote:        sqlite3.h is missing. Try 'port install sqlite3 +universal',
remote:        'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
remote:        and check your shared library search path (the
remote:        location where your sqlite3 shared library is located).
remote:        *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
remote:        libraries and/or headers.  Check the mkmf.log file for more details.  You may
remote:        need configuration options.
remote:    
remote:        Provided configuration options:
remote:        --with-opt-dir
remote:        --without-opt-dir
remote:        --with-opt-include
remote:        --without-opt-include=${opt-dir}/include
remote:        --with-opt-lib
remote:        --without-opt-lib=${opt-dir}/lib
remote:        --with-make-prog
remote:        --without-make-prog
remote:        --srcdir=.
remote:        --curdir
remote:        --ruby=/tmp/build_23334fae90f17ca215e6f12340967cbd/vendor/ruby-2.0.0/bin/ruby
remote:        --with-sqlite3-dir
remote:        --without-sqlite3-dir
remote:        --with-sqlite3-include
remote:        --without-sqlite3-include=${sqlite3-dir}/include
remote:        --with-sqlite3-lib
remote:        --without-sqlite3-lib=${sqlite3-dir}/
remote:    
remote:    
remote:        Gem files will remain installed in /tmp/build_23334fae90f17ca215e6f12340967cbd/vendor/bundle/ruby/2.0.0/gems/sqlite3-1.3.10 for inspection.
remote:        Results logged to /tmp/build_23334fae90f17ca215e6f12340967cbd/vendor/bundle/ruby/2.0.0/gems/sqlite3-1.3.10/ext/sqlite3/gem_make.out
remote:        An error occurred while installing sqlite3 (1.3.10), and Bundler cannot
remote:        continue.
remote:        Make sure that `gem install sqlite3 -v '1.3.10'` succeeds before bundling.
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  ! 
remote:  !     Detected sqlite3 gem which is not supported on Heroku.
umayneverknow
  • 190
  • 1
  • 3
  • 13

2 Answers2

3

Heroku does not support SQLite. It supports PostgreSQL by default (and some other databases with add-ons). To use PostgreSQL on Heroku, open config/database.yml and look for the production section, looking something like this:

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

Change adapter: sqlite3 to adapter: postgresql and modify the name of the database. The result should be something like:

production:
  adapter: postgresql
  database: db_production

You also need to add the PostgreSQL adapter to your Gemfile:

gem 'pg', group: [:production, :staging]

I recommend that you also configure PostgreSQL in development. Not only is SQLite much less powerful than PostgreSQL, but you also want your development environment to match production as much as possible.

eirikir
  • 3,802
  • 3
  • 21
  • 39
  • Sorry I forgot to mention. I tried doing that as well. It threw errors again. I think it has something to do with the fact that I have a class that uses `ActiveRecord::Base` – umayneverknow Sep 23 '15 at 20:33
  • Its difficult to help you when you don't explain what the errors are. The above code does work, since I've used it without issue. Also, `ActiveRecord::Base` is what all of your models inherit from – eirikir Sep 23 '15 at 20:47
  • I am getting this error when I try to run development on my local machine. ``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).`` – umayneverknow Sep 23 '15 at 20:55
  • Do exactly what it says... add `gem 'sqlite3'` to your Gemfile, but add it in the group for development, e.g. `gem 'sqlite3', group: :development` – eirikir Sep 23 '15 at 21:02
  • Yes. I did try that. But when I do, I get ``remote: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /tmp/build_23334fae90f17ca215e6f12340967cbd/vendor/ruby-2.0.0/bin/ruby extconf.rb remote: checking for sqlite3.h... no remote: sqlite3.h is missing. Try 'port install sqlite3 +universal', remote: 'yum install sqlite-devel' or 'apt-get install libsqlite3-dev' remote: and check your shared library search path (the remote: location where your sqlite3 shared library is located). remote: *** extconf.rb failed`` – umayneverknow Sep 24 '15 at 00:12
0

the comment from mu is right re: differences with ActiveRecord - you'll probably have to go back and make query changes for some things (that's what I ended up having to do!).

But if you just want to push to heroku and still be able to run it locally for testing now you should be able to just add group: :development (like below) when you want to include sqlite in your gemfile. That way heroku will ignore it when you're deploying. if this doesn't work, maybe post your database.yml file and gemfile so we can have more info

gem 'sqlite3', group: :development

ec3
  • 55
  • 1
  • 10