如何干净地删除 ndb 属性 [英] how to cleanly remove ndb properties
问题描述
在我的应用程序中,我需要删除一些模型属性.
我查看了 此链接,但第一个问题是这些属性位于 上polymodel
并且我无法切换到 expando
来删除属性,我什至不知道如果我更改 polymodel
到 expando
.
in my app i need to remove a few of my models properties.
i checked out this link but the first issue is that the properties are on a polymodel
and there is no way im going to switch to an expando
for the time to remove the properties, im not even shure what could happen if i change a polymodel
to an expando
.
那么如何从现有实体中删除属性?
so how do i remove properties from existing entities?
我想将所有 StringProperty
设置为 None
,然后从模型架构中删除它们并重新部署.其中一个属性是 BooleanProperty
,我不能将其设置为 None
对吗?!或 ndb.PickleProperty
... 我应该如何删除它?
i was thinking to set all StringProperty
to None
and then remove these from the model schema and redeploy.
one of those properties is a BooleanProperty
, i can't set this one to None
right?!
or an ndb.PickleProperty
... how should i remove that?
有人知道如何正确完成这项工作吗?
does anybody know how to get this done properly?
推荐答案
如果您想更新所有实体,推荐的方法是读取和重写所有实体的 map/reduce 作业;但是它可能不值得,这取决于你有多少数据——map/reduce 也不是免费的.
If you want to update all your entities the recommended approach is a map/reduce job that reads and rewrites all entities; however it may not be worth it, depending on how much data you have -- the map/reduce isn't free either.
还要确保在一小部分数据上测试 map/reduce 作业.从实体中真正删除一个属性是非常微妙的,即使它不再在模型类中!最好的方法可能是:
Also be sure you test the map/reduce job on a small subset of the data. It is remarkably subtle to truly remove a property from an entity, even if it's not in the model class any more! The best approach may be:
if 'propname' in ent._properties:
del ent._properties['propname']
ent.put()
这篇关于如何干净地删除 ndb 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!