Heroku postgres连接:"服务器是否在本地运行并接受Unix域套接字上的连接"

时间:2012-08-15 18:10:32

标签: sockets heroku

我正在设置一个新的开发环境,遵循django安装教程并遇到问题。这是我尝试运行syncdb时得到的结果

Running `python doccal/manage.py syncdb` attached to terminal... up, run.1
Traceback (most recent call last):
  File "doccal/manage.py", line 14, in <module>
    execute_manager(settings)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 459, in execute_manager
    utility.execute()
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/bas
e.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/bas
e.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/bas
e.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/com
mands/syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/__init_
_.py", line 306, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/postgre
sql_psycopg2/base.py", line 177, in _cursor
    self.connection = Database.connect(**conn_params)
  File "/app/.heroku/venv/lib/python2.7/site-packages/psycopg2/__init__.py", lin
e 179, in connect
    connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not connect to server: No such file or director
y
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

我在使用相同的步骤之前设置了同一个项目并且从未出现过问题。几个星期前,我收到了一封Heroku正在从共享数据库迁移出来的电子邮件,并假设这是以某种方式参与的。

另外,我注意到本教程中有两个新步骤,即安装dj-database-url并将这些行添加到settings.py

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}

我试图在有和没有这些行的情况下运行它,无论如何都会遇到同样的问题。

另一篇文章建议修复是这样做的

heroku addons:add shared-database

尝试过,收到一条消息,指出不推荐使用shared-database并使用heroku-postgresql,但这没有任何效果。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

将HOST配置为localhost,如:

'HOST': 'localhost',