如何干净地删除ndb属性 [英] how to cleanly remove ndb properties

查看:108
本文介绍了如何干净地删除ndb属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我需要删除一些模特属性。

i已签出这个链接,但第一个问题是属性在 polymodel 上,并且没有办法切换到 expando 来删除属性,即使我改变 polymodel expando



我如何从现有实体中移除属性?



i正在考虑将所有 StringProperty 设置为 None ,然后将这些从模型模式中移除并重新部署。
其中一个属性是 BooleanProperty ,我不能将这个属性设置为 None 正确?!
ndb.PickleProperty ...我应该如何删除它?



有人知道如何如果你想更新所有的实体,推荐的方法是一个map / reduce作业,它读取并重写所有实体;但它可能不值得,这取决于你有多少数据 - 地图/减少也不是免费的。



另外,请确保你测试了地图/减少一小部分数据的工作。真正从实体中删除属性非常微妙,即使它不在模型类中!最好的方法可能是:

pre $ 如果ent._properties中的'propname':
del ent._properties ['propname ']
ent.put()


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?

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?

解决方案

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.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆