为什么我得到InstrumentedAttribute而不是basequery

时间:2017-06-15 15:06:08

标签: python sqlalchemy

我使用flask_sqlalchemy在烧瓶中创建了两个模型,如下所示:

class Analytics(db.Model, IdMixin, ModelMixin):
    __tablename__ = "analytics"
    record_id = Column(Integer, ForeignKey("record.id"), nullable=True)
    created_at = Column(TIMESTAMP, nullable=True)
    updated_at = Column(TIMESTAMP, nullable=True)

class HitLog(db.Model, IdMixin, TimestampMixin, ModelMixin):
    __tablename__ = "hit_logs"
    record_id = Column(Integer, ForeignKey("record.id"), nullable=True)
    url = Column(Text, nullable=False, default='')
    ip = Column(String(100), nullable=False, default='0.0.0.0', index=True)
    referer = Column(Text, nullable=False, default='')
    source = Column(String(255), nullable=False, default='', index=True)
    query = Column(Text, nullable=False, default='')
    user_agent = Column(String(255), nullable=False, default='')
    created_at = Column(TIMESTAMP, nullable=True, index=True)
    updated_at = Column(TIMESTAMP, nullable=True, index=True)
    deleted_at = Column(TIMESTAMP, nullable=True, index=True)

两种模型的创建方式相同,但是当我检查类型时,我会得到不同的结果:

print type(Analytics.query)
print type(HitLog.query)

给我:

<class 'flask_sqlalchemy.BaseQuery'>
<class 'sqlalchemy.orm.attributes.InstrumentedAttribute'>

为什么会这样?

1 个答案:

答案 0 :(得分:0)

query中有一个名为HitLog的列。