I'm trying to run the Django on Heroku following the tutorial at:
Getting Started with Django on Heroku
Everything was running well untill I got to the syncbd part:
When I run: heroku run python manage.py syncdb
, I get the following error:
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"?
I'm currently using PostgreSQL from Homebrew, and it's running well:
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
The app server is also running 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.
And I'm working on Mac OS 10.7.
The code I'm deploying to Heroku is available here:
I've already tried a lot of possible solutions such as:
http://jeffammons.net/2011/09/fixing-postgres-on-mac-10-7-tiger-for-django/
but nothing seems to work.
EDIT:
Looking around I've found this code, and added it to the settings.py file, and it seems to solve my problem:
# 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()