Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 509
sixty4bit Avatar asked Jan 14 '14 19:01

sixty4bit


People also ask

Can you use sqlite3 with Heroku?

Heroku's Cedar stack has an ephemeral filesystem. You can write to it, and you can read from it, but the contents will be cleared periodically. If you were to use SQLite on Heroku, you would lose your entire database at least once every 24 hours. What is the difference between SQL and SQLite?

What is the difference between PostgreSQL and SQLite?

SQLite does not require a server to run. Hence, it is serverless. Server operating systems for PostgreSQL are FreeBSD, Linux, OS X, Solaris and Windows.


1 Answers

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

like image 155
ChrisBarthol Avatar answered Nov 13 '22 09:11

ChrisBarthol