【问题标题】:Unable to fetch data from View's columns无法从 View 的列中获取数据
【发布时间】:2015-03-02 14:25:24
【问题描述】:

我正在尝试使用 SQLAlchemy 反映来自 MySQL 数据库的视图。反射后,我试图从视图中获取数据,但它不起作用。 我的 initializedb.py 中有以下代码:

dev=DBSession2.execute("select project from myView where code='1223'").first()

temp=str(dev.project)

当我初始化数据库时,我得到了这个错误

AttributeError: 'ResultProxy' object has no attribute 'project'

以下是在我的models.py中反映myView的代码:

Base2=declarative_base()
engine2= create_engine('mysql://<pathtomydb>')
meta=MetaData()
meta.reflect(bind=engine2)
class myView(Base2):
    __table__=Table('myView',meta,Column('id', Integer, primary_key=True),autoload=True,autoload_with=engine2)
    __tablename__='myView'

我已经反映了另外两个表,它们工作正常。谁能告诉我为什么这个观点没有得到反映?

【问题讨论】:

    标签: python mysql sqlalchemy


    【解决方案1】:

    您可以尝试删除所有库并重新安装守护程序和要求。这一定是您的配置错误。

    【讨论】:

    • 这并没有提供问题的答案。要批评或要求作者澄清,请在其帖子下方发表评论。
    • 我认为这将解决她的问题,所以它是可能的答案。
    • 嗨,我不认为这是一个错误配置,因为我能够从其他反射表中获取列...只有这个视图无法访问。
    猜你喜欢
    • 2016-12-09
    • 2012-09-18
    • 1970-01-01
    • 2015-09-26
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 2019-08-24
    • 1970-01-01
    相关资源
    最近更新 更多