attributeError:无法使用flask-SQLAlchemy设置属性 [英] attributeError: can't set attribute with flask-SQLAlchemy

查看:266
本文介绍了attributeError:无法使用flask-SQLAlchemy设置属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flask-SQLAlchemy 2.1版,该版本安装了sqlalchemy 1.x版.

I'm using Flask-SQLAlchemy version 2.1 which installs sqlalchemy version 1.x.

下面的代码首先获取结果集数组,然后循环修改现有的可工作属性,但现在不起作用了.

My below code which first fetch an array of resultset and then loop over to modify an existing attribute used to work but now it does not.

question_topic = Question.query.join(Topic).join(User,User.id==Question.user_id).add_columns(User.email,Question.question, Question.date, Topic.topic_name, Question.id, Topic.question_id)\
        .filter(Question.id == Topic.question_id).all()



for q_t in question_topic:
    q_t.topic_name = q_t.topic_name + "some text..."

我收到以下错误: attributeError:无法使用'topic_name'设置属性

I get following error: attributeError: can't set attribute with 'topic_name'

推荐答案

我在新列上遇到了相同的错误("AttributeError:无法设置属性"错误).这是由于我之前添加了@property,并且其名称与该列相同.

I had the same error ("AttributeError: can't set attribute" error) on a new column. It was due to a @property that I had previously added and that had the same name than the column.

这篇关于attributeError:无法使用flask-SQLAlchemy设置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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