Rails 4 - how to use sqlite3 in development and PostgreSQL in production w/Heroku

11,746

Don't do it. You are just going to run into problems down the road. Use the same database in production and development. There are a lot of resources available in documenting the switch from a sqlite to postgres database.

Take the time and switch.

Have a look at this Rails Cast.

http://railscasts.com/episodes/342-migrating-to-postgresql?view=asciicast

Share:
11,746
sixty4bit
Author by

sixty4bit

Updated on July 18, 2022

Comments

  • sixty4bit
    sixty4bit almost 2 years

    I am trying to deploy to Heroku but can't because the default sqlite3 server is still in place.

    Detected sqlite3 gem which is not supported on Heroku. https://devcenter.heroku.com/articles/sqlite3

    In another tutorial with Rails 3.2.13 I was able to use sqlite3 as the dev db and Postgres as the production db. The Gemfile looks different in Rails 4 but I have modified it to have this:

    group :development do
      # Use sqlite3 as the database for Active Record
      gem 'sqlite3'
    end
    
    group :production do
      gem 'pg'
    end
    

    I then changed my database.yml file so that the production section looked like this:

    production:
      adapter: postgresql
      database: my_production_database
      pool: 5
      timeout: 5000
    

    I then ran bundle install and rake db:create and rake db:migrate but am still unable to push to Heroku. So I tried rake db:drop as well as rake db:create and rake db:migrate but am still getting the same error message.

    Am I missing something? What else do I need to do to make sure I'm getting Postgres as my production database and am able to use Heroku?

  • sixty4bit
    sixty4bit over 10 years
    I think I found the problem. I'm just a newbie and forgot that I have to commit my changes to git first before deploying to heroku. This time I was able to deploy to Heroku successfully but now none of my styling is showing up (I have bootstrap installed).
  • Justin
    Justin over 10 years
    Alright. in your console, run bundle exec rake assets:precompile. Then run git add public/assets -f. then commit your changes and try again. devcenter.heroku.com/articles/rails-asset-pipeline
  • Marko Jurinčič
    Marko Jurinčič over 10 years
    Also add this gem 'rails_12factor', '0.0.2' to your production group
  • David Aldridge
    David Aldridge over 10 years
    I believe that the production section of database.yml is ignored on Heroku -- it substitutes the values with its own based on the user, password and database that you create as part of the app.
  • sixty4bit
    sixty4bit over 10 years
    Thanks for the tip! I originally had been using different ones because that's how it was set up on a tutorial I was following. I guess you can't trust everything that's published as a tutorial!
  • ChrisBarthol
    ChrisBarthol over 10 years
    It is one of if not the biggest flaw of some of the tutorials out there. It "works" for the tutorial, but once you do something beyond it you'll run into trouble. If you are followingMichael Hartl Rails Tutorial he leaves it as an exercise: ruby.railstutorial.org/chapters/…
  • sixty4bit
    sixty4bit over 10 years
    The answer to my original question was that I wasn't committing to git before deploying to Heroku but I'm marking this as the answer since it seems to be the 'best practices' answer to the underlying problem.
  • sixty4bit
    sixty4bit over 10 years
    I have tried bundle exec rake assets:precompile as well as adding rails_12factor to my Gemfile but it's still not working. Guess I'll make a new post