title: django postgres could not connect to server
body: <p>hi im working on a django project with virtualenv that is using the following 
      Django==1.7.6
      argparse==1.2.1
      psycopg2==2.6
      wsgiref==0.1.2</p>
  
  <p>but when i try <code>python manage.py runserver</code> it gives me this error </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Performing system checks...
  
  System check identified no issues (0 silenced).
  Unhandled exception in thread started by &lt;function wrapper at 0x7f0574e8c0c8&gt;
  Traceback (most recent call last):
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 222, in wrapper
      fn(*args, **kwargs)
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
      self.check_migrations()
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 159, in check_migrations
      executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
      self.loader = MigrationLoader(self.connection)
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
      self.build_graph()
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 183, in build_graph
      self.applied_migrations = recorder.applied_migrations()
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
      self.ensure_schema()
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
      if self.Migration._meta.db_table in self.connection.introspection.get_table_list(self.connection.cursor()):
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 165, in cursor
      cursor = self.make_debug_cursor(self._cursor())
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 138, in _cursor
      self.ensure_connection()
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
      self.connect()
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
      six.reraise(dj_exc_type, dj_exc_value, traceback)
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
      self.connect()
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 122, in connect
      self.connection = self.get_new_connection(conn_params)
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 130, in get_new_connection
      connection = Database.connect(**conn_params)
    File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
      conn = _connect(dsn, connection_factory=connection_factory, async=async)
  django.db.utils.OperationalError: could not connect to server: Connection refused
   Is the server running on host "127.0.0.1" and accepting
   TCP/IP connections on port 5432?</code></pre>
  </div>
  </div>
  </p>
  
  <p>my settings.py is </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
          'NAME': 'elfmsdb',
          'USER': 'postgres',
          'PASSWORD': '',
          'HOST': '127.0.0.1',
          'PORT': '5432',
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>i also checked the postgresql.conf and it is using 5432 as port. </p>
  
  <p>another odd thing is that i accidentally runserver outside my virtualenv and it worked but the django version is 1.6. </p>
  
  <p>please help me, thanks a lot! </p>