7

I have noticed a method:

db.reflect(bind='__all__',app=app)

but I wonder how to use it.
I'd appreciate it if you can help.

0

1 Answer 1

7
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'database connect url'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
db.Model.metadata.reflect(bind=db.engine,schema='DATABASE_NAME')

class User(db.Model):
    '''deal with an existing table'''
    __table__ = db.Model.metadata.tables['DATABASE_NAME.TABLE_NAME']

u = User.query.all()
print(u)
db.commit()

Sign up to request clarification or add additional context in comments.

1 Comment

this code will not work if you are having multiple schemas..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.