Search code examples
postgresqlherokuflaskheroku-postgres

Difficulties installing Postgres on Flask


Getting the following error when trying to run. Just recently trying to move from SQLite to PostGres on Flask so that I can host on Heroku.

 File "XXXXXX/Desktop/hubbub/flask/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 377, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/Users/jianglin/Desktop/hubbub/flask/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
OperationalError: (OperationalError) FATAL:  database "XXXXX/Desktop/hubbub/app.db" does not exist
 None None

I have been using the following tutorial thus far for most my database stuff: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database

Sorry if this is a basic question, I am new to the world of Flask. My guess is this has something to do with me not creating the database, but I am not sure how given the format of this tutorial. trying to create via db_create gives me the same error.


Solution

  • The part of your error message that is important is probably this:

    FATAL: database "XXXXX/Desktop/hubbub/app.db" does not exist

    An ending in .db is usually something you would do with SQLite, not with Postgres. Try looking for wherever you specify the database settings and change it to the correct setting for Heroku's DB instance. Note: while SQLite can be specified with just a file location, Postgres needs to have username/password/location/database information. Here is a sample:

    SQLALCHEMY_DATABASE_URI = "postgresql://yourusername:yourpassword@localhost/yournewdb"