[Rails6]Production環境でrails db:reset ,db:dropができない時
今回は下記を参考にさせていただきました。
はじめに
Railsアプリの本番環境でrails db:reset
を実行した所以下のエラーが出ました。
$ rails db:migrate:reset RAILS_ENV=production
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
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate:reset => db:drop => db:check_protected_environments
(See full trace by running task with --trace)
原因
Rails5からはproduction環境で破壊的処理(内容は以下に記述)をすることができなくなっている。
db:drop
db:drop:all
db:reset
db:purge
db:purge:all
db:purge:test
db:schema:load
解決方法
ヒントはエラーメッセージに記載されている。
$ rails db:migrate:reset RAILS_ENV=production
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 ←ここ
環境変数としてDISABLE_DATABASE_ENVIRONMENT_CHECK=1
を指定することでコマンドを実行することができます。
$ rails db:migrate:reset RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1
Dropped database 'hogehoge_production'
Created database 'hogehoge_production'
== 20210311185651 DeviseCreateUsers: migrating ================================
以上です。
Author And Source
この問題について([Rails6]Production環境でrails db:reset ,db:dropができない時), 我々は、より多くの情報をここで見つけました https://qiita.com/Jackson123/items/feec782f6deb7fdc15c3著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .