title: How to add postgresql to the gem file?
body: <p>I cannot add pg to gem file.</p>
  
  <p>what I did:
  changed</p>
  
  <pre><code>gem 'sqlite3'
  </code></pre>
  
  <p>to </p>
  
  <pre><code>group :development, :test do
    gem 'sqlite3'
  end
  
  group :production do
    gem 'pg'
  end
  </code></pre>
  
  <p>I try to deploy this rails app on heroku
  I also did:</p>
  
  <pre><code>gem install bundler
  bundle install --without production
  git add .
  git commit -m"blahblah"
  git push heroku master
  </code></pre>
  
  <p>However, after I ran:</p>
  
  <pre><code>heroku run rails db:migrate
  </code></pre>
  
  <p>Here is the error I got:</p>
  
  <pre><code> Caused by:
   Gem::LoadError: pg is not part of the bundle. Add it to your Gemfile.
   /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/rubygems_integration.rb:377:in `block (2 levels) in replace_gem'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:2:in `&lt;top (required)&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:186:in `spec'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:880:in `establish_connection'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_handling.rb:58:in `establish_connection'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/railtie.rb:124:in `block (2 levels) in &lt;class:Railtie&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:69:in `instance_eval'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:49:in `each'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/base.rb:326:in `&lt;module:ActiveRecord&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/base.rb:25:in `&lt;top (required)&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/mysql_database_tasks.rb:6:in `&lt;class:MySQLDatabaseTasks&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/mysql_database_tasks.rb:3:in `&lt;module:Tasks&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/mysql_database_tasks.rb:2:in `&lt;module:ActiveRecord&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/mysql_database_tasks.rb:1:in `&lt;top (required)&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:74:in `&lt;module:DatabaseTasks&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:35:in `&lt;module:Tasks&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:2:in `&lt;module:ActiveRecord&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:1:in `&lt;top (required)&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/railtie.rb:34:in `block (3 levels) in &lt;class:Railtie&gt;'
  /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:21:in `block in perform'
  /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
  /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/command.rb:46:in `invoke'
  /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `&lt;top (required)&gt;'
  /app/bin/rails:4:in `require'
  /app/bin/rails:4:in `&lt;main&gt;'
  Tasks: TOP =&gt; db:migrate =&gt; db:load_config
  (See full trace by running task with --trace)
  </code></pre>
  
  <p>And here is my gem file:</p>
  
  <pre><code>source 'https://rubygems.org'
  
  git_source(:github) do |repo_name|
    repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
    "https://github.com/#{repo_name}.git"
  end
  
  
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
  gem 'rails', '~&gt; 5.1.4'
  # Use sqlite3 as the database for Active Record
  group :development, :test do
    gem 'sqlite3'
  end
  
  group :production do
    gem 'pg'
  end
  
  # Use Puma as the app server
  gem 'puma', '~&gt; 3.7'
  # Use SCSS for stylesheets
  gem 'sass-rails', '~&gt; 5.0'
  # Use Uglifier as compressor for JavaScript assets
  gem 'uglifier', '&gt;= 1.3.0'
  # See https://github.com/rails/execjs#readme for more supported runtimes
  # gem 'therubyracer', platforms: :ruby
  
  # Use CoffeeScript for .coffee assets and views
  gem 'coffee-rails', '~&gt; 4.2'
  # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
  gem 'turbolinks', '~&gt; 5'
  # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
  gem 'jbuilder', '~&gt; 2.5'
  # Use Redis adapter to run Action Cable in production
  # gem 'redis', '~&gt; 3.0'
  # Use ActiveModel has_secure_password
  # gem 'bcrypt', '~&gt; 3.1.7'
  
  # Use Capistrano for deployment
  # gem 'capistrano-rails', group: :development
  
  group :development, :test do
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console
    gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
    # Adds support for Capybara system testing and selenium driver
    gem 'capybara', '~&gt; 2.13'
    gem 'selenium-webdriver'
  end
  
  group :development do
    # Access an IRB console on exception pages or by using &lt;%= console %&gt; anywhere in the code.
    gem 'web-console', '&gt;= 3.3.0'
  end
  
  # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
  gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
  </code></pre>