gpt4 book ai didi

ruby-on-rails - Rails 5 如何清除或删除生产 postgres 数据库

转载 作者:数据小太阳 更新时间:2023-10-29 06:33:38 28 4
gpt4 key购买 nike

我正在尝试删除生产数据库,以便重新开始。当我从 rails 4 升级到 rails 5 时,它现在正在保护生产数据库不被意外删除。它在我运行 rake db:reset 时显示以下错误消息。

/app# rake db:reset
ActiveRecord::SchemaMigration Load (1.8ms) SELECT "schema_migrations".* FROM "schema_migrations"
(1.6ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", :environment]]
ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
(0.3ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", :environment]]
ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
(0.2ms) SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 [["key", :environment]]
rake 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-5.0.0.1/lib/active_record/tasks/database_tasks.rb:51:in `check_protected_environments!'
/usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/railties/databases.rake:11:in `block (2 levels) in <top (required)>'
/usr/local/bundle/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:reset => db:drop => db:check_protected_environments
(See full trace by running task with --trace)

它说我在命令中添加环境变量 DISABLE_DATABASE_ENVIRONMENT_CHECK=1 应该有效,但实际上无效。我运行它,但它什么也没做。

<606723-x9dh4:/app# DISABLE_DATABASE_ENVIRONMENT_CHECK=1 rake db:reset       
ActiveRecord::SchemaMigration Load (1.6ms) SELECT "schema_migrations".* FROM "schema_migrations"

有人知道我做错了什么吗?感谢您的帮助!

更新:

我的服务器是使用 kubernetes 部署的。我猜我无法重置数据库,因为服务器正在运行。

最佳答案

试试这个对我有用:

RAILS_ENV=production rake db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1 

在一行中。

关于ruby-on-rails - Rails 5 如何清除或删除生产 postgres 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40775611/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com