I'm running a python 3.5 worker on heroku.
self.engine = create_engine(os.environ.get("DATABASE_URL"))
My code works on local, passes Travis CI, but gets an error on heroku - OperationalError: (psycopg2.OperationalError) FATAL: database "easnjeezqhcycd" does not exist
.
easnjeezqhcycd
is my user, not database name. As I'm not using flask's sqlalchemy, I haven't found a single person dealing with the same person
I tried destroying my addon database and created standalone postgres db on heroku - same error.
What's different about heroku's URL that SQLAlchemy doesn't accept it? Is there a way to establsih connection using psycopg2 and pass it to SQLAlchemy?
Old question, but the answer seems to be that database_exists
and create_database
have special case code for when the engine URL starts with postgresql
, but if the URL starts with just postgres
, these functions will fail. However, SQLAlchemy in general works fine with both variants.
So the solution is to make sure the database URL starts with postgresql://
and not postgres://
.