I've notice a method:
db.reflect(bind='__all__',app=app)
but i wonder how to use it.
I'd appreciate it if you can help.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With