Search code examples
ruby-on-railspostgresqlsqliterails-postgresql

Rails: Sqlite with PG gem


I installed postgres on my Mac and tried it for the first time with Rails. I included gem "pg" and removed the sqlite3 gem (after all, why would you need the latter if using the former). However, when I tried to start the server I got this error message

.rvm/gems/ruby-1.9.3-rc1@rails321/gems/bundler-1.0.22/lib/bundler/rubygems_integration.rb:143:in `block in replace_gem': Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (sqlite3 is not part of the bundle. Add it to Gemfile.) (LoadError)

So I included the sqlite3 gem again and now the server works fine, but I actually don't have any idea if my test app is using sqlite3 or pg?

a) Am I supposed to have the sqlite3 gem installed if I'm planning on using the pg gem? b) If I'm only supposed to have one of the two installed, is there a way to find out which one my test app is currently using (since both of them are in the Gemfile)

Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.1'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'pg'
gem 'devise'
gem 'sqlite3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer'

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

Solution

  • Here was my database.yml when i was working with the pg gem, the adapter is actually called postgresql and there are a couple other differences in the settings, if you just copy and paste the code below and change the database names you should be pretty much ready (I used heroku, this worked there):

    development:
      adapter: postgresql
      encoding: utf8
      reconnect: false
      database: DATABASE_DEVELOPMENT
      pool: 5
      username: USER_NAME
      password:
      host: localhost
    
    test:
      adapter: postgresql
      encoding: utf8
      reconnect: false
      database: DATABASE_TEST
      pool: 5
      username: USER_NAME
      password:
      host: localhost
    
    production:
      adapter: postgresql
      encoding: utf8
      reconnect: false
      database: DATABASE_PRODUCTION
      pool: 5
      username: root
      password: