40

I'm trying to deploy my first app to Heroku. I'm using SQLite as the database. As far as I know Heroku doesn't use SQLite - it switches to Postgres in the backend.

When I'm deploying I get the following error:

/usr/ruby1.8.7/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in `require': no such file to load -- sqlite3 (LoadError)

My Gemfile (which is what I assume is causing this problem) looks as follows:

source 'http://rubygems.org'

gem 'rails', '3.0.0'        
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'

What am I doing wrong?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Jaco Pretorius
  • 24,380
  • 11
  • 62
  • 94
  • And what about running it locally? I have sqlite in all my gem files and have no problems with heroku. Did you bundle? – Art Shayderov Oct 09 '10 at 19:59
  • I don't think I quite understand the concept of bundling. What does bundling do? (A link will do) – Jaco Pretorius Oct 10 '10 at 11:39
  • Duplicate of [Pushing Rails with SQLite3 to Heroku fails](http://stackoverflow.com/questions/3747002/pushing-rails-with-sqlite3-to-heroku-fails) –  May 25 '14 at 20:51

7 Answers7

53

Heroku doesn't support SQLite databases. You need to use PostgreSQL on production, as I also explained in this post.

group :production do
  gem "pg"
end

group :development, :test do
  gem "sqlite3", "~> 1.3.0"
end

Actually, it's recommended to use in development/test an environment as close as possible to production. Therefore, I suggest you to switch all your environments to PostgreSQL.

# replace gem "sqlite3" with
gem "pg"
Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
  • Are you sure? I'm following along in RailsTutorial.org - the author deploys to Heroku without changing anything – Jaco Pretorius Oct 10 '10 at 11:43
  • 4
    Thanks, I have no idea why the stupid tutorial doesn't mention that – Jaco Pretorius Oct 10 '10 at 18:28
  • 1
    Jaco/Simone, Heroku doesn't require that you reference PostgreSQL in your Gemfile however, and will ignore references to anything else in your database.yml file. I have an DB-based app running there with no specific reference to PG and it works just fine. That's why the book doesn't mention it. – Joost Schuur Oct 11 '10 at 05:27
  • 42
    I was wrestling with this for a while (I'm also following the railstutorial.org) and no matter what I did, it wasn't helping. Of course after plenty of wasted time, **I then realized I had forgotten to add and commit my newly edited Gemfile to the git repo**. Hopefully that helps someone avoid running into the same problem. – waffl Mar 26 '12 at 22:24
  • 1
    I see by the upvotes that I'm not the only one to feel stupid after reading the comment above. Thanks @waffl – Jason Feb 26 '13 at 22:21
  • And you also need to be careful that the branch you're pushing to Heroku is the same branch your Gemfile is committed on. This is a subtle variation on the same issue, and made me feel silly when I found it answered over at http://stackoverflow.com/questions/14474213 . – AlexC Sep 24 '14 at 20:43
4

Simone Carletti is correct and so is Joost. You only need to group the sqlite3 gem or remove it entirely from your Gemfile. Heroku just needs to know that you don't want to use sqlite3 for production

So this:

...
group :development, :test do
  gem "sqlite3-ruby", "~> 1.3.0", :require => "sqlite3"
end
...

Or this:

...
#No reference to sqlite3-ruby
...

If you remove the reference entirely you will probably mess up your local db though

hoitomt
  • 41
  • 1
1

After banging my head against this problem, I realized I was pushing the master branch of my repo to heroku, while I was making all of my postgres changes in my deploy-postgres branch of my repo!

I merged my deploy-postgres branch with my local master [git checkout master; git merge deploy-postgres] and then could run git push heroku master as per the heroku documentation.

duhaime
  • 25,611
  • 17
  • 169
  • 224
0

I was stuck on this for hours looking at every answer here, but I couldn't get enough details to make it come together. This paged walked me through everything. http://railsapps.github.io/rails-heroku-tutorial.html

Good luck.

Sangaku
  • 95
  • 1
  • 6
0

i was facing similar issue, but I realized that I was on a different branch - new_layout and was pushing master. So I pushed my desired branch to heroku using following command and everything worked fine.

git push heroku new_layout:master 
Milind
  • 4,535
  • 2
  • 26
  • 58
-2

You can use clearDB addon

and gem 'mysql2' instead of gem 'sqlite3'

Community
  • 1
  • 1
Katya
  • 138
  • 10
-5

I'm using sqlite3 and deploy to Heroku no problem. Here is my database.yml

# SQLite version 3.x
#   gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# 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:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000
lucapette
  • 20,564
  • 6
  • 65
  • 59
  • 7
    The database.yml file doesn't matter - "To ease deployment of typical Rails applications, Heroku automatically generates a new database.yml file on deployment" – Jaco Pretorius Oct 10 '10 at 18:37