文章内容
2022/7/28 18:09:57,作 者: 黄兵
AttributeError: 'ForeignKey' object has no attribute 'is_clause_element'
今天使用 SQLAlchemy 的时候出现了如下错误:
AttributeError: 'ForeignKey' object has no attribute 'is_clause_element'
出现问题的原因:
通过查询官方文档,解释为:True if this object is an instance of InstanceState
.
不明所以。
同时我检查了这张表,具体出现错误的字段为:
account_funds_id = db.relationship(db.Integer, db.ForeignKey('cloud_product_account_funds.id'))
这个不应该使用 db.relationship
,而应该使用 db.Column
。
解决方案:
修改模型字段:
account_funds_id = db.Column(db.Integer, db.ForeignKey('cloud_product_account_funds.id'))
再次运行程序,问题解决。
参考资料:
1、SQLAlchemy 1.4 Documentation
黄兵个人博客原创。
转载请注明出处:黄兵个人博客 - AttributeError: 'ForeignKey' object has no attribute 'is_clause_element'
评论列表