I have a running Flask app with the following structure:
myproject/
myapp.py
models.py
I can run the app locally, and I can access it in a debugger (Pycharm for the curious). I am unable to fire up the db instance in the python interpreter and I need to be able to access the working objects to debug.
Here is what I am doing in the interpreter.
import sys
sys.path.append('/path/to/myproject/')
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
from models import db, User, Post
app = Flask('myapp')
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://localhost/mydb'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
I can call on the classes User and Post. If I, however, try to use query to access the underlying db, say User.query.all(), I am given
RuntimeError: application not registered on db instance and no application bound to current context
What needs to be done to get the interpreter to be able to access the db that is found when running from myapp.py? I don't think that I need all of the statements that I am using, but am struggling to find the right sequence of magic words to make the interpreter behave like my IDE.