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.
asked Mar 10, 2019 at 2:41
1 Answer 1
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()
answered Mar 10, 2019 at 13:26
-
this code will not work if you are having multiple schemas..Shivam Chaurasia– Shivam Chaurasia04/26/2022 08:26:01Commented Apr 26, 2022 at 8:26
lang-py