如何在Heroku上进行rake db:drop和rake db:create?[英] How to rake db:drop and rake db:create on Heroku?

本文是小编为大家收集整理的关于如何在Heroku上进行rake db:drop和rake db:create?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

可能的重复:
如何在heroku中空db

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

但是,当我尝试在heroku上运行它时,我会得到错误:

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

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

推荐答案

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

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

本文地址:https://www.itbaoku.cn/post/597421.html

问题描述

Possible Duplicate:
How to empty DB in 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.

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

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?

推荐答案

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

$ 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:reset command would try to drop the database, which is not something that Heroku's permissions allow.