I am connected to a MS SQL Server. The following returns all the table names in the database:
app.config.from_object('config')
db = SQLAlchemy(app)
db.engine.table_names()
However, this doesn't:
db.metadata.tables.keys() // returns: dict_keys([])
Similarly, this doesn't work:
db.table('dbo.users').primary_key // returns: ColumnSet([])
However, I am able to execute SQL queries. What would be the problem?
Engine.table_names
gives you a list of available table names from the database. Metadata.tables
is a mapping of declared tables associated with the metadata.
If you want to populate the metadata with what's available in the database, use reflection :
db.metadata.reflect(bind=db.engine)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.