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