[英]python sqlalchemy union query,'Query' object has no attribute 'spends'
[英]SQLAlchemy for Python, 'Query' object has no attribute 'fetchone'
我正在與一位程序員一起進行以數據庫為中心的項目。 我們有以下代碼從數據庫中檢索信息:
# create connection to database
engine = create_engine(URL(**DATABASE))
Session = sessionmaker(bind=engine)
session = Session()
# construct query
query = session.query(MediaText.line_number, MediaText.start_time_stamp, MediaText.end_time_stamp).\
filter(MediaText.oclc_id == oclcId)
# get info about first line to snapshot
line_to_snapshot = query.fetchone()
當我嘗試運行代碼時,出現以下錯誤:
AttributeError:“查詢”對象沒有屬性“ fetchone”
令人困惑的是,我的伴侶可以很好地運行代碼。 我們都在運行Python 3.4,並且在我們的系統上具有SQLAlchemy庫的1.0.9版本。 有人知道這里可能出什么問題嗎?
從SQLALchemy的Query API以及據我所知(Python 2.7和fetchone
1.0.4) fetchone
並不是Query
API的一部分,盡管是one
。
如何將其更改為:
line_to_snapshot = query.one()
看看是否line_to_snapshot = query.one()
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.