AWS(EC2)へデプロイ後にデータベースを破棄しようとした際に発生
ec2-user@ip-*** ~]$ docker exec -it ***** sh
# rails db:drop 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
/usr/local/bundle/gems/activerecord-6.1.5/lib/active_record/tasks/database_tasks.rb:63:in `check_protected_environments!'
/usr/local/bundle/gems/activerecord-6.1.5/lib/active_record/railties/databases.rake:18:in `block (2 levels) in <main>'
/usr/local/bundle/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
production環境でデータベースをdropする際は、DISABLE_DATABASE_ENVIRONMENT_CHECK=1
を環境変数として指定します。
コンテナ内に入る
[ec2-user@ip-**-** ~]$ docker exec -it ***** sh
rails db:dropを実行
# rails db:drop RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1
Dropped database 'myapp_production'