database 如何在 Heroku 上 rake db:drop 和 rake db:create?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10990104/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:34:29  来源:igfitidea点击:

How to rake db:drop and rake db:create on Heroku?

databasepostgresqlherokurake

提问by Geoff

Possible Duplicate:
How to empty DB in heroku

可能的重复:
如何在 heroku 中清空数据库

I have a Postgres database on Heroku. It is one of the free beta ones. Locally, when testing, I often run rake db:drop && rake db:create && rake db:migrate as a way to reset the database.

我在 Heroku 上有一个 Postgres 数据库。它是免费的测试版之一。在本地,在测试时,我经常运行 rake db:drop && rake db:create && rake db:migrate 作为重置数据库的一种方式。

However, when I try to run this on Heroku, I get the error:

但是,当我尝试在 Heroku 上运行它时,出现错误:

Couldn't drop mydatabaseid : #<PG::Error: FATAL:  permission denied for database "postgres"
  DETAIL:  User does not have CONNECT privilege.

Uh, ok, so how am I supposed to completely reset my database, migrations and everything?

嗯,好的,那么我应该如何完全重置我的数据库、迁移和所有内容?

回答by Neil Middleton

The pg:resetcommand will recreate the database for you. Example usage:

pg:reset命令将为您重新创建数据库。用法示例:

$ heroku config | grep POSTGRESQL
HEROKU_POSTGRESQL_RED_URL: postgres://somedatabaseurl
$ heroku pg:reset HEROKU_POSTGRESQL_RED_URL
!    WARNING: Destructive Action
!    This command will affect the app: myappname
!    To proceed, type "myappname" or re-run this command with --confirm
> myappname
Resetting HEROKU_POSTGRESQL_RED_URL (DATABASE_URL)... done

The db:resetcommand would try to drop the database, which is not something that Heroku's permissions allow.

db:reset命令将尝试删除数据库,这不是 Heroku 权限允许的。