Advertisement
Guest User

Untitled

a guest
Jul 26th, 2012
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. Deploying Django to Heroku (Psycopg2 Error)
  2. heroku run python manage.py syncdb
  3.  
  4. psycopg2.OperationalError: could not connect to server: Connection refused
  5. Is the server running on host "localhost" and accepting
  6. TCP/IP connections on port 5432?
  7.  
  8. heroku addons:add shared-database:5mb
  9.  
  10. import sys
  11. import urlparse
  12. import os
  13.  
  14.  
  15. # Register database schemes in URLs.
  16. urlparse.uses_netloc.append('postgres')
  17. urlparse.uses_netloc.append('mysql')
  18.  
  19. try:
  20.  
  21. # Check to make sure DATABASES is set in settings.py file.
  22. # If not default to {}
  23.  
  24. if 'DATABASES' not in locals():
  25. DATABASES = {}
  26.  
  27. if 'DATABASE_URL' in os.environ:
  28. url = urlparse.urlparse(os.environ['DATABASE_URL'])
  29.  
  30. # Ensure default database exists.
  31. DATABASES['default'] = DATABASES.get('default', {})
  32.  
  33. # Update with environment configuration.
  34. DATABASES['default'].update({
  35. 'NAME': url.path[1:],
  36. 'USER': url.username,
  37. 'PASSWORD': url.password,
  38. 'HOST': url.hostname,
  39. 'PORT': url.port,
  40. })
  41. if url.scheme == 'postgres':
  42. DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
  43.  
  44. if url.scheme == 'mysql':
  45. DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
  46. except Exception:
  47. print 'Unexpected error:', sys.exc_info()
  48.  
  49. psycopg2
  50.  
  51. toplevel
  52. requirements.txt
  53. myapp
  54. manage.py
  55. all other django stuff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement