我試圖在Heroku上運行的Django的教程如下:與Django的Heroku上PostgreSQL的應用程序是否未同步
Getting Started with Django on Heroku
一切都運行良好,直到我到了syncbd部分:
當我運行:heroku run python manage.py syncdb
,我得到以下錯誤:
psycopg2.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
我目前使用PostgreSQL從家釀,它的運行良好:
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
應用服務器還運行localy:
Validating models...
0 errors found
Django version 1.4.1, using settings 'hellodjango.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
而且我工作在Mac OS 10.7。
我部署到Heroku的代碼可以在這裏找到:
我已經嘗試了很多可能的解決方案,如:
http://jeffammons.net/2011/09/fixing-postgres-on-mac-10-7-tiger-for-django/
,但似乎沒有上班。
編輯:
環顧四周,我發現這個代碼,並將其添加到settings.py文件,它似乎解決我的問題:
# Register database schemes in URLs.
urlparse.uses_netloc.append('postgres')
urlparse.uses_netloc.append('mysql')
try:
if 'DATABASES' not in locals():
DATABASES = {}
if 'DATABASE_URL' in os.environ:
url = urlparse.urlparse(os.environ['DATABASE_URL'])
# Ensure default database exists.
DATABASES['default'] = DATABASES.get('default', {})
# Update with environment configuration.
DATABASES['default'].update({
'NAME': url.path[1:],
'USER': url.username,
'PASSWORD': url.password,
'HOST': url.hostname,
'PORT': url.port,
})
if url.scheme == 'postgres':
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
if url.scheme == 'mysql':
DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
except Exception:
print 'Unexpected error:', sys.exc_info()
我很新,感謝您解釋它! – Filipe