1
1

More than 3 years have passed since last update.

今まで出たherokuエラー、躓いた事などまとめ

Last updated at Posted at 2020-07-30

今まで出たherokuのエラー

その1

error: src refspec master does not match any

解決方法

pushするブランチを間違っていた。作業しているブランチがdevelopだったのでdevelopと書きその後に:masterとつけるのが決まりみたい。

$ git push heroku develop:master

その2

herokuにデプロイしたアプリのDBをリセットする方法

これじゃダメらしい
$ heroku run rails db:migrate:reset
正しい方法
$ heroku pg:reset DATABASE_URL

 WARNING: Destructive action
 ▸    postgresql-convex-62654 will lose all of its data
 ▸    
 ▸    To proceed, type secure-savannah-48652 or re-run this command with
 ▸    --confirm secure-savannah-48652

> secure-savannah-48652←なんか色々出るけどここにアプリ名を打ち込む

Resetting postgresql-convex-62654... done

その3

herokuに環境変数を設定する

1.envが使える前提の場合
環境変数をまとめてセットする

$ heroku config:set $(cat .env)←.envの部分は必要に応じて.env.developmentなどに変える必要もあると思われる

2.herokuの公式ページから設定する場合
以下にアクセスして、環境変数を設定したいアプリを選択し、環境変数を設定する

https://dashboard.heroku.com/apps

3環境変数をまとめて削除する
これ良くわかんなかったけど一応記載。1の方法で環境変数を上書き出来るからあまり必要なさそう

$ heroku config -s | cut -d= -f1 | xargs heroku config:remove

その4

環境変数を設定したのにheroku run rails db:seedでエラーが出る。環境変数が反映されていないようだった。

DEVELOPMENT_SMART_YOYAKU_URL='http://localhost:3000'
PRODUCTION_SMART_YOYAKU_URL='https://smartyoyakupotalsite.herokuapp.com'

DEVELOPMENT_SMART_PORTAL_URL='http://localhost:4000'
PRODUCTION_SMART_PORTAL_URL='https://secure-savannah-48652.herokuapp.com'

RESAS_API='7FrTYfKCKrCfbWmBFw8OHhXBZzwpl6LUR8R3ZK'

LINE_KEY='1654658496'
LINE_SECRET='4ed72a5dbea0f9b457d91868be60cec5'
GOOGLE_APP_ID='446815084334-7neovd7n7440a24j6r3m2l2t9j9uulvm.apps.googleusercontent.com'
GOOGLE_APP_SECRET='TpNZUg2Ck9oZsi_GsKJ44ssY_'


RESAS_APIの’’を消したら反映された
RESAS_API=7FrTYfKCKrCfbWmBFw8OHhXBZzwpl6LUR8R3ZK

そもそもENVファイルに定義する時''で囲む必要はないみたい。

その5

# git push heroku master

remote: !   No such app as murmuring-dawn-5953.
fatal: repository 'https://git.heroku.com/murmuring-dawn-5953.git/' not found

前のherokuにあげたアプリのurlの設定のままになっているとかなんとか・・
もう一度セットしたいアプリのurlをセットする必要がある。

まずはセットしたいアプリのurlを調べる

$ heroku apps

infinite-springs-58936
polar-ocean-01270
$ heroku info --app infinite-springs-58936 ←urlを調べたいアプリ名

=== infinite-springs-58936
Auto Cert Mgmt: false
Dynos:          
Git URL:        https://git.heroku.com/infinite-springs-58936.git
Owner:          jun09079695178_1218@yahoo.co.jp
Region:         us
Repo Size:      0 B
Slug Size:      0 B
Stack:          heroku-18
Web URL:        https://infinite-springs-58936.herokuapp.com/

urlがわかったら実際にセットしていく

$ git remote set-url heroku https://git.heroku.com/infinite-springs-58936.git

これでgit push heroku masterができるはず。

その6

$ git push heroku master

Missing encryption key to decrypt file with. Ask your team for your master key and write it to /tmp/build_1f68f016/config/master.key or put it in the ENV['RAILS_MASTER_KEY'].

なんかmaster.keyって奴が必要らしい。こいつはrails newした時に作られるらしい。通常git ignoreに入っており、git pushした時にリモートリポジトリに上がらないようになっている。herokuにpushする際、こいつは別で読み込ませる必要があるらしい。

もしconfig/master.keyというファイルがあれば以下のコマンドでherokuに読み込ませることができる。

$ heroku config:set RAILS_MASTER_KEY=`cat config/master.key`

ない場合はconfig/credentials.yml.encというファイルを削除後、以下のコマンドを実行して再生成する。
credentials.yml.encとは?
https://qiita.com/yamamoto_shuji/items/5afd9ffe13f36ff29677

$ rails credentials:edit
無理だったら以下を打ち込む
$ EDITOR="vim" bin/rails credentials:edit
or
$ EDITOR="mate --wait" bin/rails credentials:edit

これでconfig配下にmaster.keyとcredentials.yml.encファイルが追加されるはず。

参考記事:https://stackoverflow.com/questions/54064347/rails-during-asset-precompile-throws-error-key-must-be-16-bytes

その7

$ git push heroku feat/ad_api:master

Caused by: remote: OpenSSL::Cipher::CipherError: heroku

解決方法

この時はもう一度コミットしてから、git push heroku masterしたら通りました。

その8

Caused by:
remote:        LoadError: cannot load such file -- active_record/connection_adapters/mysql_adapter

active_record/connection_adapters/mysql_adapterなんてファイルないとか言われている。

結論

herokuに設定していたDATABASE_URLが間違っていた。公式サイトから確認可能
https://dashboard.heroku.com/

今回本番環境で使用するのはmysql2な訳で勘違いしてgem 'pg'を使用していたことも原因だった。mysqlをherokuで使うにはそれに合わせた設定が必要になる。

設定の仕方/https://qiita.com/poster-keisuke/items/f27e190e22d80dc254ed

cinfig/database.tml

production:
  adapter: mysql2
  database: <%= ENV['RDS_DB_NAME'] %>
  username: <%= ENV['RDS_USERNAME'] %>
  password: <%= ENV['RDS_PASSWORD'] %>
  host: <%= ENV['RDS_HOSTNAME'] %>
  port: <%= ENV['RDS_PORT'] %>

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1