I used the answer to this question to fix a circular import when setting up Flask-SQLAlchemy. The solution works because you don't have to import the app
from the application.py
file to get the database URI - it initalizes the connection just before running the app. The issue now is that I typically like import my models
file into a python interpreter just so I can test the models (and the connection to the database) without actually running the app. But with this setup, just importing models
won't establish a connection to PostGres.
Is there a way to establish a connection to PostGres through Flask-SQLAlchemy
without actually initializing and running an app? Maybe I can provide db
with the URI to my database directly?