Reputation: 2693
I'm configuring a new app in rails5 on my localhost and am having some trouble establishing my environment. I set my environment variable to "development" but whenever I run rake db:drop
it says the following
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
However my environment is set to development and not production:
sam$ printenv | grep RAILS_ENV
RAILS_ENV=development
What am I forgetting?
Many thanks for taking a look at this.
EDIT: My yaml looks like this
default: &default
adapter: mysql2
encoding: utf8
username: ZZZZZZZ
database: YYYYYYY
host: 127.0.0.1
socket: /tmp/mysql.sock
password: XXXXXXXXX
development:
<<: *default
reconnect: true
Upvotes: 4
Views: 2334
Reputation: 40780
In case the DB you wanted to drop was a production copy, the ar_internal_metadata
would hold the value production
and rails db:drop
throws the error you see. Running migrate changes the value to development
rails db:migrate
...
ActiveRecord::InternalMetadata Update (0.4ms) UPDATE "ar_internal_metadata" SET "value" = $1, "updated_at" = $2 WHERE "ar_internal_metadata"."key" = $3 [["value", "development"]
...
Now you can drop db without error. No point on importing then dropping perhaps, but I got this error now after having played around with data in local rails console and wanted to drop and restore data.
Upvotes: 2
Reputation: 2699
You could set the environment using
bin/rails db:environment:set RAILS_ENV=development
Upvotes: 7