向现有 Google AppEngine 数据模型/实体添加新属性时出现问题
在 GAE 中,我有一个名为 Foo 的模型,其中包含现有实体,并尝试向 Foo 添加一个名为 memcached 的新属性,该属性采用上次将此值设置为 memcache 时的日期时间值。 如果我尝试对此属性进行查询和排序,甚至过滤没有 memcached 值的实体,则不会返回尚未为此属性设置值的实体。 我在这里缺少什么,或者作为替代方案,是否有一种快速方法可以为给定模型的每个实体上的 new 属性设置值?
我创建了以下模型的一堆实体,
class Foo(db.Model):
name = db.StringProperty(required=True)
然后向该模型添加一个属性,
class Foo(db.Model):
name = db.StringProperty(required=True)
memcached = db.DateTimeProperty(required=True, auto_now=True, auto_now_add=True, default=datetime.min)
当我对查询进行排序或过滤时,不考虑新属性的默认值。
In GAE, I have a model called Foo, with existing entities, and attempt to add a new property called memcached to Foo that takes datetime values for the last time this value was set to memcache. If I try to query and sort on this property, or even filter for entities that do not have a value for memcached, entities that haven't had a value set for this property yet are not returned. Is there something I'm missing here, or as an alternative, is there a quick way to set a value for a new property on every entity of a given model?
I have created a bunch of entities of the following model,
class Foo(db.Model):
name = db.StringProperty(required=True)
and then add a property to this model,
class Foo(db.Model):
name = db.StringProperty(required=True)
memcached = db.DateTimeProperty(required=True, auto_now=True, auto_now_add=True, default=datetime.min)
the default value of the new property is not considered when I do a sort or filter on a query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了遍历每个现有实体并添加属性之外,没有什么办法,这里是官方文档将引导您完成整个过程。
There's nothing for it but to go through each of your existing entities and add the property, here is the official documentation which walks you through the process.