Skip to content

Reflecting Tables, "'autoload_with': db.engine" working outside context #1133

Answered by TRezendes
TRezendes asked this question in Q&A
Discussion options

You must be logged in to vote

I spent about a day trying to sort this problem out before I posted this question, but I should have given myself a couple more hours. I am going to answer my own question in case anyone else comes looking.

I was able to resolve my "outside of application context" error with the following changes (in bold italic) to my models.py:

models.py


from appname_app import argon2, db, create_app
from flask_login import UserMixin
from sqlalchemy.dialects import postgresql
from sqlalchemy import PrimaryKeyConstraint

app = create_app()
with app.app_context():        
    class UserInfoTbl(db.Model):
        __tablename__ = 'user_info'
        __table_args__ = {
            'autoload':True,
         …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by TRezendes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant