Ruby-on-rails 在 Heroku Cedar 堆栈上运行 rake db:drop db:create db:migrate
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8162420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running rake db:drop db:create db:migrate on Heroku Cedar stack
提问by John
When I try to run:
当我尝试运行时:
heroku run rake db:drop db:create db:migrate
I get the error:
我收到错误:
Running rake db:drop attached to terminal... up, run.5
Couldn't drop adsfsadfas : #<ActiveRecord::StatementInvalid: PGError: ERROR: must be owner of database adsfsadfas
: DROP DATABASE IF EXISTS "adsfsadfas">
I am on the Heroku Cedar stack. Am I allowed to drop databases on Heroku?
我在 Heroku Cedar 堆栈上。我可以删除 Heroku 上的数据库吗?
Thanks!
谢谢!
John
约翰
回答by Francisco Soto
The rake db:reset task is not supported. Heroku apps do not have permission to drop and create databases. Use the
heroku pg:resetcommand instead.
不支持 rake db:reset 任务。Heroku 应用程序无权删除和创建数据库。请改用
heroku pg:reset命令。
回答by schmijos
Directly destructive commands (dropand create) are not permitted on heroku. But if you're ok with loosing all the data, you can reset the database with pg:reset.
heroku 上不允许直接破坏性命令(drop和create)。但是,如果您可以丢失所有数据,则可以使用pg:reset.
heroku pg:reset DATABASE_URL
Every other change should be done with db:migrate. This assures consistency of the database state.
所有其他更改都应该使用db:migrate. 这确保了数据库状态的一致性。
If your migrations don't run through the full stack anymore you can use db:schema:load. This loads the schema directly from schema.rb. But be aware that this can also be destructive if create_tableuses the parameters force: trueor force: :cascade.
如果您的迁移不再通过完整堆栈运行,您可以使用db:schema:load. 这直接从schema.rb加载架构。但请注意,如果create_table使用参数force: true或,这也可能是破坏性的force: :cascade。
heroku run rake db:schema:load

