0

我可以像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.

我使用dj_database_url.config的是:https ://github.com/heroku/python-getting-started/blob/33fafbd40ff5532def4ce7b3d0ebc1c7e34a0be7/gettingstarted/settings.py#L115

我的完整项目: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 网站目前只是一种向他人展示想法的方式,那里的数据可以被丢弃。

4

1 回答 1

2

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

于 2016-06-07T21:09:18.577 回答