Heroku refuses connection to postgres database
<p>I am trying to deploy my Flask app based on PostgreSQL on Heroku, but I when I try to create the table with <code>db.create_all()</code> I keep getting this error:</p>

<pre><code>(psycopg2.OperationalError) could not connect t
rver: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
</code></pre>

<p>Here is how my code looks like:</p>

<pre><code>app=Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI']='postgres://kfgriimpfjecsv:Bk1*****G@localhost:5432/dd71doth8gopgh'
db=SQLAlchemy(app)
if __name__ == '__main__':
    app.debug=True
    app.run()
</code></pre>

<p>I am using Heroku Toolbelt to communicate with Heroku servers. Also, when I try this: </p>

<pre><code>psql -p 5432 -h localhost
</code></pre>

<p>I get almost the same error: </p>

<pre><code>psql: could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
</code></pre>

<p>I also tried <code>ec2-23-21-215-184.compute-1.amazonaws.com</code> instead of <code>localhost</code> in the URI, but got the same error.</p>

<p>And <a href="https://www.dropbox.com/s/nxr1tgeivpyk0tt/traceback.txt?dl=0" rel="nofollow">here</a> is the complete traceback that I get when I run db.create_all(): </p>

<p>Any idea why the connection is being refused and how to solve this?</p>