我正在尝试将烧杯缓存与SQLAlchemy一起使用,但我一直收到错误。
这是我的表格定义。
class Post(Base):
....
....
user = relation(User, primaryjoin = User.id == id)
tags = relation( Tags , backref = posts )
class Tags(Base):
...
...
user = relation(User, primaryjoin = User.id == id)
post = relation(Post, primaryjoin = Post.id == id)
烧杯缓存可以与除这些类之外的其他SQLAlchemy类一起使用。
当我运行程序时,我收到以下错误;
DetachedInstanceError: Parent instance <Post at 0x101f90b10> is not bound 到a Session; lazy load operation of attribute user cannot proceed.
我在StackOverFlow上搜索过,在另一个线程中发现我需要禁用延迟加载,所以我更改了行
user = relation(User, primaryjoin = User.id == id)
到
user = relation(User, primaryjoin = User.id == id, lazy= dynamic )
but this occurs 到following error in template(post.user.fullname
);
AttributeError: AppenderQuery object has no attribute fullname
我做错了什么?