LoginSignup
11
8

More than 3 years have passed since last update.

【heroku】MySQL本番環境のデータベースをリセットさせる方法

Last updated at Posted at 2020-06-17

herokuのデータベースリセット

ターミナル.
heroku run rails db:migrate:reset

上記コマンドで、heroku上のデータベースをリセットできます。
しかし、Rails5から本番環境データベース保護機能が追加され,上記コマンドのみだと下記の内容で怒られる。

エラー.
rails aborted!
ActiveRecord::ProtectedEnvironmentError: You are attempting to run a destructive action against your 'production' database.
If you are sure you want to continue, run the same command with the environment variable:
DISABLE_DATABASE_ENVIRONMENT_CHECK=1

環境変数を指定して実行してください〜と

解決方法

解決方法として、
RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1を追加入力でOKです。

ターミナル.
$ heroku run rails db:migrate:reset RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1

ちなみに、、、
MySQLでなくPostgreSQLを使っている場合は下記でリセット可能です。

ターミナル.
$ heroku pg:reset DATABASE
$ heroku run rake db:migrate

恥ずかしながら僕は、MySQLを使っているのに$ heroku pg:reset DATABASEを何度も打ってしまい上手くいかず躓いてしましました...

参考になれば幸いです。

11
8
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
11
8