将 SQLAlchemy 查询的结果存储在数组中

问题描述 投票:0回答:1

我试图将 SQLAlchemy 语句的结果存储在数组中。但它给了我属性错误。请帮忙。

qry = (db.session.query(Customer))    
print(qry)

results = [
    {
        
        "customerID": getModelField(row.Customer, "id"),
        "network": getModelField(row.Customer, "network_num"),
        "customer": getModelField(row.Customer,"customer_name"),
        "email": getModelField(row.Customer, "customer_email"),
             
    }
    for row in qry.all()
]

out = {"results": results, "total": len(results)}

在控制台中,我收到 - AttributeError: 'Customer' object has no attribute 'Customer'

python sqlalchemy model
1个回答
1
投票

查询结果的每一行都是一个

Customer
对象。请尝试
row.id
获取您的 ID 等等。

© www.soinside.com 2019 - 2024. All rights reserved.