heroku error while deploying Rails app

#問題
<a href="https://railstutorial.jp/chapters/beginning?version=5.0#sec-deploying" target="_blank">Herokuへのデプロイ記事</a>を参考にしながら`git push heroku master`すると`sqlite`周りのエラーが原因
でデプロイが出来ない

実際のエラー:

```
Counting objects: 88, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (73/73), done.
Writing objects: 100% (88/88), 20.59 KiB | 0 bytes/s, done.
Total 88 (delta 3), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.2.6
remote: -----> Installing dependencies using bundler 1.13.7
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Fetching gem metadata from https://rubygems.org/.........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Installing i18n 0.8.0
remote:        Installing concurrent-ruby 1.0.4
remote:        Installing rake 12.0.0
remote:        Installing minitest 5.10.1
remote:        Installing thread_safe 0.3.5
remote:        Installing builder 3.2.3
remote:        Installing erubis 2.7.0
remote:        Installing mini_portile2 2.1.0
remote:        Installing rack 2.0.1
remote:        Installing nio4r 1.2.1 with native extensions
remote:        Installing websocket-extensions 0.1.2
remote:        Installing mime-types-data 3.2016.0521
remote:        Installing arel 7.1.4
remote:        Installing coffee-script-source 1.12.2
remote:        Installing execjs 2.7.0
remote:        Installing method_source 0.8.2
remote:        Installing thor 0.19.4
remote:        Installing multi_json 1.12.1
remote:        Using bundler 1.13.7
remote:        Installing puma 3.4.0 with native extensions
remote:        Installing sass 3.4.23
remote:        Installing tilt 2.0.6
remote:        Installing sqlite3 1.3.11 with native extensions
remote:        Installing turbolinks-source 5.0.0
remote:        Installing tzinfo 1.2.2
remote:        Installing nokogiri 1.7.0.1 with native extensions
remote:        Installing rack-test 0.6.3
remote:        Installing sprockets 3.7.1
remote:        Installing websocket-driver 0.6.5 with native extensions
remote:        Installing mime-types 3.1
remote:        Installing coffee-script 2.4.1
remote:        Installing uglifier 3.0.0
remote:        Installing turbolinks 5.0.1
remote:        Installing activesupport 5.0.0.1
remote:        Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
remote:        /tmp/build_6c03bd70fa1a32409262114840940734/vendor/ruby-2.2.6/bin/ruby -r
remote:        ./siteconf20170211-283-l673kg.rb extconf.rb
remote:        checking for sqlite3.h... no
remote:        sqlite3.h is missing. Try 'port install sqlite3 +universal',
remote:        'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
remote:        and check your shared library search path (the
remote:        location where your sqlite3 shared library is located).
remote:        *** extconf.rb failed ***
remote:        Could not create Makefile due to some reason, probably lack of necessary
remote:        libraries and/or headers.  Check the mkmf.log file for more details.  You may
remote:        need configuration options.
remote:        Provided configuration options:
remote:        --with-opt-dir
remote:        --without-opt-dir
remote:        --with-opt-include
remote:        --without-opt-include=${opt-dir}/include
remote:        --with-opt-lib
remote:        --without-opt-lib=${opt-dir}/lib
remote:        --with-make-prog
remote:        --without-make-prog
remote:        --srcdir=.
remote:        --curdir
remote:        --ruby=/tmp/build_6c03bd70fa1a32409262114840940734/vendor/ruby-2.2.6/bin/$(RUBY_BASE_NAME)
remote:        --with-sqlite3-dir
remote:        --without-sqlite3-dir
remote:        --with-sqlite3-include
remote:        --without-sqlite3-include=${sqlite3-dir}/include
remote:        --with-sqlite3-lib
remote:        --without-sqlite3-lib=${sqlite3-dir}/lib
remote:        extconf failed, exit code 1
remote:        Gem files will remain installed in
remote:        /tmp/build_6c03bd70fa1a32409262114840940734/vendor/bundle/ruby/2.2.0/gems/sqlite3-1.3.11
remote:        for inspection.
remote:        Results logged to
remote:        /tmp/build_6c03bd70fa1a32409262114840940734/vendor/bundle/ruby/2.2.0/extensions/x86_64-linux/2.2.0-static/sqlite3-1.3.11/gem_make.out
remote:        An error occurred while installing sqlite3 (1.3.11), and Bundler cannot
remote:        continue.
remote:        Make sure that `gem install sqlite3 -v '1.3.11'` succeeds before bundling.
remote:        Bundler Output: Fetching gem metadata from https://rubygems.org/.........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Installing i18n 0.8.0
remote:        Installing concurrent-ruby 1.0.4
remote:        Installing rake 12.0.0
remote:        Installing minitest 5.10.1
remote:        Installing thread_safe 0.3.5
remote:        Installing builder 3.2.3
remote:        Installing erubis 2.7.0
remote:        Installing mini_portile2 2.1.0
remote:        Installing rack 2.0.1
remote:        Installing nio4r 1.2.1 with native extensions
remote:        Installing websocket-extensions 0.1.2
remote:        Installing mime-types-data 3.2016.0521
remote:        Installing arel 7.1.4
remote:        Installing coffee-script-source 1.12.2
remote:        Installing execjs 2.7.0
remote:        Installing method_source 0.8.2
remote:        Installing thor 0.19.4
remote:        Installing multi_json 1.12.1
remote:        Using bundler 1.13.7
remote:        Installing puma 3.4.0 with native extensions
remote:        Installing sass 3.4.23
remote:        Installing tilt 2.0.6
remote:        Installing sqlite3 1.3.11 with native extensions
remote:        Installing turbolinks-source 5.0.0
remote:        Installing tzinfo 1.2.2
remote:        Installing nokogiri 1.7.0.1 with native extensions
remote:        Installing rack-test 0.6.3
remote:        Installing sprockets 3.7.1
remote:        Installing websocket-driver 0.6.5 with native extensions
remote:        Installing mime-types 3.1
remote:        Installing coffee-script 2.4.1
remote:        Installing uglifier 3.0.0
remote:        Installing turbolinks 5.0.1
remote:        Installing activesupport 5.0.0.1
remote:        Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
remote:
remote:        /tmp/build_6c03bd70fa1a32409262114840940734/vendor/ruby-2.2.6/bin/ruby -r
remote:        ./siteconf20170211-283-l673kg.rb extconf.rb
remote:        checking for sqlite3.h... no
remote:        sqlite3.h is missing. Try 'port install sqlite3 +universal',
remote:        'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
remote:        and check your shared library search path (the
remote:        location where your sqlite3 shared library is located).
remote:        *** extconf.rb failed ***
remote:        Could not create Makefile due to some reason, probably lack of necessary
remote:        libraries and/or headers.  Check the mkmf.log file for more details.  You may
remote:        need configuration options.
remote:
remote:        Provided configuration options:
remote:        --with-opt-dir
remote:        --without-opt-dir
remote:        --with-opt-include
remote:        --without-opt-include=${opt-dir}/include
remote:        --with-opt-lib
remote:        --without-opt-lib=${opt-dir}/lib
remote:        --with-make-prog
remote:        --without-make-prog
remote:        --srcdir=.
remote:        --curdir
remote:        --ruby=/tmp/build_6c03bd70fa1a32409262114840940734/vendor/ruby-2.2.6/bin/$(RUBY_BASE_NAME)
remote:        --with-sqlite3-dir
remote:        --without-sqlite3-dir
remote:        --with-sqlite3-include
remote:        --without-sqlite3-include=${sqlite3-dir}/include
remote:        --with-sqlite3-lib
remote:        --without-sqlite3-lib=${sqlite3-dir}/lib
remote:
remote:        extconf failed, exit code 1
remote:
remote:        Gem files will remain installed in
remote:        /tmp/build_6c03bd70fa1a32409262114840940734/vendor/bundle/ruby/2.2.0/gems/sqlite3-1.3.11
remote:        for inspection.
remote:        Results logged to
remote:        /tmp/build_6c03bd70fa1a32409262114840940734/vendor/bundle/ruby/2.2.0/extensions/x86_64-linux/2.2.0-static/sqlite3-1.3.11/gem_make.out
remote:
remote:        An error occurred while installing sqlite3 (1.3.11), and Bundler cannot
remote:        continue.
remote:        Make sure that `gem install sqlite3 -v '1.3.11'` succeeds before bundling.
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !     Detected sqlite3 gem which is not supported on Heroku:
remote:  !     https://devcenter.heroku.com/articles/sqlite3
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed
remote: Verifying deploy....
remote:
remote: !	Push rejected to intense-garden-69636.
remote:
To https://git.heroku.com/intense-garden-69636.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/intense-garden-69636.git'
```

#原因1: Gemfile
Gemfileを正しく書き換えていなかった。調べてみると分かるようにHerokuは本番データベースを使用する際、sqliteではなくpostgressを推奨している。よってテスト環境ではsqliteを、本番ではpostgressを使うように指示してあげなければならなかった。

```Gemfile
group development :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', '9.0.0', platform: :mri
  gem 'sqlite3', '1.3.11'
end

group :production do
  gem 'pg', '0.18.4'
end
```

`bundle install --without production`、`git add .`そして`git commit -m "update Gemfile"`も行う。

#原因2: Gitでマージし忘れていた

>Problem solved. It was actually a problem with how I was using git. I had created a new branch to make the changes from sqlite to ppsql and I was trying to push to heroku from that branch. Turns out when you say "git push heroku master" it isn't pushing from your current branch, it is pushing from the master branch. Which in my case was still configured to use sqlite. To solve this problem first merge with your master branch before pushing to heroku.

`git push heroku master`は自分の作業ブランチからのデプロイではなくあくまで現在のmasterブランチからのデプロイを行う。つまり作業ブランチを直したところで__masterとマージさせなければ何も意味がない。__

```
$ git checkout master
$ git merge [your working branch]
```

参照: <a href="http://stackoverflow.com/a/27152044/5922520" target="_blank">Removed sqlite gem but Heroku still detects sqlite gem and fails</a>

#エラー解消

```
Counting objects: 100, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (85/85), done.
Writing objects: 100% (100/100), 21.68 KiB | 0 bytes/s, done.
Total 100 (delta 12), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.2.6
remote: -----> Installing dependencies using bundler 1.13.7
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Fetching gem metadata from https://rubygems.org/.........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Installing i18n 0.8.0
remote:        Installing concurrent-ruby 1.0.4
remote:        Installing rake 12.0.0
remote:        Installing minitest 5.10.1
remote:        Installing thread_safe 0.3.5
remote:        Installing builder 3.2.3
remote:        Installing mini_portile2 2.1.0
remote:        Installing erubis 2.7.0
remote:        Installing rack 2.0.1
remote:        Installing nio4r 1.2.1 with native extensions
remote:        Installing websocket-extensions 0.1.2
remote:        Installing mime-types-data 3.2016.0521
remote:        Installing arel 7.1.4
remote:        Installing coffee-script-source 1.12.2
remote:        Installing execjs 2.7.0
remote:        Installing method_source 0.8.2
remote:        Installing thor 0.19.4
remote:        Installing multi_json 1.12.1
remote:        Installing pg 0.18.4 with native extensions
remote:        Installing puma 3.4.0 with native extensions
remote:        Using bundler 1.13.7
remote:        Installing sass 3.4.23
remote:        Installing tilt 2.0.6
remote:        Installing turbolinks-source 5.0.0
remote:        Installing tzinfo 1.2.2
remote:        Installing nokogiri 1.7.0.1 with native extensions
remote:        Installing rack-test 0.6.3
remote:        Installing sprockets 3.7.1
remote:        Installing websocket-driver 0.6.5 with native extensions
remote:        Installing mime-types 3.1
remote:        Installing coffee-script 2.4.1
remote:        Installing uglifier 3.0.0
remote:        Installing turbolinks 5.0.1
remote:        Installing activesupport 5.0.0.1
remote:        Installing mail 2.6.4
remote:        Installing globalid 0.3.7
remote:        Installing activemodel 5.0.0.1
remote:        Installing jbuilder 2.4.1
remote:        Installing activejob 5.0.0.1
remote:        Installing activerecord 5.0.0.1
remote:        Installing rails-dom-testing 2.0.2
remote:        Installing loofah 2.0.3
remote:        Installing rails-html-sanitizer 1.0.3
remote:        Installing actionview 5.0.0.1
remote:        Installing actionpack 5.0.0.1
remote:        Installing actionmailer 5.0.0.1
remote:        Installing actioncable 5.0.0.1
remote:        Installing railties 5.0.0.1
remote:        Installing sprockets-rails 3.2.0
remote:        Installing coffee-rails 4.2.1
remote:        Installing rails 5.0.0.1
remote:        Installing sass-rails 5.0.6
remote:        Installing jquery-rails 4.1.1
remote:        Bundle complete! 16 Gemfile dependencies, 53 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Bundle completed (24.61s)
remote:        Cleaning up the bundler cache.
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        I, [2017-02-11T23:39:55.065677 #1149]  INFO -- : Writing /tmp/build_33ecf5c5ef3804b1f97100509b5b3aba/public/assets/application-db5fed084311c4f37b7088efa1db9925ddf5cd86e135ad019fea6c0bc4abebae.js
remote:        I, [2017-02-11T23:39:55.070810 #1149]  INFO -- : Writing /tmp/build_33ecf5c5ef3804b1f97100509b5b3aba/public/assets/application-db5fed084311c4f37b7088efa1db9925ddf5cd86e135ad019fea6c0bc4abebae.js.gz
remote:        I, [2017-02-11T23:39:55.078683 #1149]  INFO -- : Writing /tmp/build_33ecf5c5ef3804b1f97100509b5b3aba/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css
remote:        I, [2017-02-11T23:39:55.079047 #1149]  INFO -- : Writing /tmp/build_33ecf5c5ef3804b1f97100509b5b3aba/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz
remote:        Asset precompilation completed (3.78s)
remote:        Cleaning assets
remote:        Running: rake assets:clean
remote:
remote: ###### WARNING:
remote:        You have not declared a Ruby version in your Gemfile.
remote:        To set your Ruby version add this line to your Gemfile:
remote:        ruby '2.2.6'
remote:        # See https://devcenter.heroku.com/articles/ruby-versions for more information.
remote:
remote: ###### WARNING:
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server
remote:
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console, rake, web, worker
remote:
remote: -----> Compressing...
remote:        Done: 27.8M
remote: -----> Launching...
remote:        Released v5
remote:        https://intense-garden-69636.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/intense-garden-69636.git
```