且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Vague Flask-SQLAlchemy错误:"AttributeError:mapper"

更新时间:2023-02-01 08:48:00

好的,所以我找到了解决方法.

Okay, so I found a solution.

我查看了堆栈跟踪,打开了/home/nicken/freelance/project/lib/python3.4/site-packages/sqlalchemy/orm/relationships.py,然后转到第1709行.

I looked at the stacktrace, opened up /home/nicken/freelance/project/lib/python3.4/site-packages/sqlalchemy/orm/relationships.py and went to line 1709.

然后我在第1709行上方放置了print(self)语句,这为我提供了有关问题出在哪里的更多信息.

I then put a print(self) statement just above line 1709, and that gave me more information as to where the problem was.

结果...在代码的其他地方,在其他一些模型定义中,我有类似db.relationship('foo.bar.etc.SomeModel')的内容,并且传递给db.relationship()的引用不再有效,因为所引用的模型具有被移到其他地方.

It turns out... elsewhere in my code, in some other model definitions, I had something like db.relationship('foo.bar.etc.SomeModel') and the reference that was being passed to db.relationship() was not valid any more, because model being referred to had been moved somewhere else.

这就是我修复它的方式.

And that's how I fixed it.