Google app engine返回“BadRequestError:在事务中只允许祖先查询”。这在代码上下文中是什么意思:
class Counter(db.Model):
totalRegistrations = db.IntegerProperty(default=0)
@db.transactional
def countUsers():
counter = Counter.all().get()
counter.totalRegistrations = counter.totalRegistrations + 1
counter.put()
i = counter.totalRegistrations
return i
print countUsers()
这仅仅意味着用
Counter.all().get()
运行的查询不是祖先查询。在这种情况下,应该使用从事务方法中提取计数器的查询,如下所示:这意味着您首先获取对计数器的引用,但只获取值并将其放入事务方法中,从而保证原子性。你知道吗
相关问题 更多 >
编程相关推荐