Flask-SQLAlchemy数据库引擎返回表名称,但元数据中的表键为空 [英] Flask-SQLAlchemy database engine returns table names, but the table keys in metadata are empty

查看:53
本文介绍了Flask-SQLAlchemy数据库引擎返回表名称,但元数据中的表键为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已连接到MS SQL Server.以下返回数据库中的所有表名:

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()

但是,这不是:

db.metadata.tables.keys() // returns: dict_keys([])

类似地,这不起作用:

db.table('dbo.users').primary_key // returns: ColumnSet([])

但是,我能够执行SQL查询.怎么了?

However, I am able to execute SQL queries. What would be the problem?

推荐答案

Engine.table_names 为您提供了数据库中可用表名的列表. Metadata.tables 是与元数据关联的声明的表的映射.

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)

这篇关于Flask-SQLAlchemy数据库引擎返回表名称,但元数据中的表键为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆