在学习Bluelog项目时,制作数据库模型,最后再整合到forge()命令后,会报错:
sqlalchemy.exc.ArgumentError: Error creating backref 'post' on relationship 'Post.comments': property of that name exists on mapper 'mapped class Comment->comment'
从github上下载了源代码,看到问题所在:
在Post类中,文章与评论的关系设置,
书中是:comments = db.relationship('Comment', backref='post', cascade='all, delete-orphan')
源码是:comments = db.relationship('Comment', back_populates='post', cascade='all, delete-orphan')
将其改成源码,即问题解决。
请问,是什么原因呀? 谢谢啦