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.

asked Mar 10, 2019 at 2:41
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()
answered Mar 10, 2019 at 13:26
1
  • this code will not work if you are having multiple schemas.. Commented Apr 26, 2022 at 8:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.