Django 1.3.1 Heroku Postgres 错误

标签 django postgresql heroku django-settings

我们最近将我们的网站推到了暂存状态,从那以后一直在努力让它恢复正常,而 Heroku 的团队并没有真正及时做出回应,所以我转向社区看看是否有快速修复。

我们废弃了旧的并设置了一个仍然存在相同问题的新堆栈

heroku config
DISABLE_INJECTION: 1

settings.py

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydb',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
        'PORT': '',
        'HOST': 'localhost'
    },
}

这是完整的轨迹。

heroku run python myapp/manage.py syncdb

Traceback (most recent call last):
  File "fundedbyme/manage.py", line 11, in <module>
    execute_manager(settings)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/app/.heroku/venv/lib/python2.7/site-packages/south/management/commands/syncdb.py", line 90, in handle_noargs
    syncdb.Command().execute(**options)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 56, in handle_noargs
    cursor = connection.cursor()
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 252, in cursor
    cursor = util.CursorWrapper(self._cursor(), self)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 140, in _cursor
    self.connection = Database.connect(**conn_params)
  File "/app/.heroku/venv/lib/python2.7/site-packages/psycopg2/__init__.py", line 179, in connect
    connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not connect to server: Connection refused
    Is the server running on host "localhost" and accepting
    TCP/IP connections on port 5432?

最佳答案

DATABASES = {
    'default': dj_database_url.config(default=os.environ.get('DATABASE_URL'))
}

关于Django 1.3.1 Heroku Postgres 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13064782/

相关文章:

python - Fabric 将应用程序部署到代理服务器

python - 无法获取 Django 模板来打印格式化 JSON

postgresql - 用 Ecto 改变 Postgres search_path

postgresql - 如何在 Heroku 上为 Postgres 命令启用安静模式

node.js - 看到错误模块未找到 : 'pg-native' in heroku app

django - Heroku 推送失败并出现奇怪的错误消息

python - 如何将 Django 模型发送到带有附加自定义字段的模板中?

mysql - 删除相关记录的记录

python - 让flask-sqlalchemy使用db.create_all从模型创建表

ssl - 在 Heroku 上使用 PointDNS 管理 SSL 和非 www 到 www 重定向