1

我们最近将我们的网站推到了暂存状态,并且从那以后一直在努力启动它,而 Heroku 的团队并没有真正及时做出响应,所以我正在求助于社区,看看是否有快速修复。

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

heroku config
DISABLE_INJECTION: 1

设置.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?
4

3 回答 3

2
DATABASES = {
    'default': dj_database_url.config(default=os.environ.get('DATABASE_URL'))
}
于 2012-10-26T17:30:40.970 回答
1

确保你的 Heroku 上有 Postgres:

heroku addons:add heroku-postgresql:dev

找出数据库 url 环境变量。它看起来像这样:HEROKU_POSTGRESQL__URL

heroku config | grep POSTGRESQL

更新您的设置

import dj_database_url
import os 

POSTGRES_URL = "HEROKU_POSTGRESQL_<COLOR>_URL"
DATABASES = {'default': dj_database_url.config(default=os.environ[POSTGRES_URL])}

鲍勃是你的叔叔。

我在 heroku 上为 django 准备了一个方便的引导程序。这可能会有所帮助:https ://github.com/callmephilip/django-heroku-bootstrap

愉快的部署

于 2012-10-26T17:22:42.833 回答
0

尝试这个:

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://myuser:mypassword@localhost:5432/mydb')}
于 2012-10-25T12:27:13.767 回答