如何从Heroku上的django-extensions运行reset_db?失败:“用户没有CONNECT权限。”

时间:2016-06-05 11:23:43

标签: python django heroku django-extensions

我可以正常执行heroku run python manage.py migrate之类的数据库操作,但是reset_db失败了:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python3.5/site-packages/django_extensions/management/utils.py", line 58, in inner
    ret = func(self, *args, **kwargs)
  File "/app/.heroku/python/lib/python3.5/site-packages/django_extensions/management/commands/reset_db.py", line 145, in handle
    connection = Database.connect(**conn_params)
  File "/app/.heroku/python/lib/python3.5/site-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATAL:  permission denied for database "template1"
DETAIL:  User does not have CONNECT privilege.

我正在使用https://github.com/heroku/python-getting-started/blob/33fafbd40ff5532def4ce7b3d0ebc1c7e34a0be7/gettingstarted/settings.py#L115

中提到的dj_database_url.config

我的完整项目:https://github.com/cirosantilli/free-books-django-raw/tree/1fd154df716e06e02a5a3afa299a89fe5513a112

在问题跟踪器上:https://github.com/django-extensions/django-extensions/issues/909

在Django 1.9.6上测试,django-extensions 1.6.7。

目标:清理Heroku数据库,然后运行一个命令,用我修改过的测试数据集填充它。 Heroku网站目前只是向其他人展示想法的一种方式,那里的数据可以被扔掉。

1 个答案:

答案 0 :(得分:1)

不要使用reset_db命令 - 它执行“drop”和“create”,我怀疑它与Heroku授予的权限不相符。更好的是使用内置的Heroku命令pg:reset。例如:heroku pg:reset DATABASE_URL。有关详细信息,请参阅https://devcenter.heroku.com/articles/heroku-postgresql#pg-reset