2012-10-25 70 views
1

我們最近把我們的網站推到了舞臺上,並一直在努力爭取它,而Heroku的團隊沒有及時做出響應,所以我轉向社區瞭解是否有一個快速修復。Django 1.3.1 Heroku Postgres error

我們報廢的舊的和相同的問題

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? 
+0

它在做什麼,你說什麼:連接到本地主機端口5432是本地主機上的數據庫服務器?我的印象是Heroku的數據庫與應用程序服務器不在同一臺主機上。 –

+0

Heroku數據庫服務器不在本地主機上!請參閱Django的文檔:https://devcenter.heroku.com/articles/django#database-settings –

回答

0

試試這個:

import dj_database_url 
DATABASES = {'default': dj_database_url.config(default='postgres://myuser:[email protected]:5432/mydb')} 
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])} 

鮑勃是你的叔叔。

我把一個方便的django bootstrap放在heroku上。它可能會有所幫助:https://github.com/callmephilip/django-heroku-bootstrap

快樂部署

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