0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Rails] 本番環境でrails db:dropする

Posted at

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'
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?