迁移NDB模型属性的正确方法 [英] Proper way to migrate NDB model property

查看:80
本文介绍了迁移NDB模型属性的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在NDB中有一个模型,我想更改属性名称而不必接触NBD.假设我有以下内容:

I currently have a model in NDB and I'd like to change the property name without necessarily touching NBD. Let's say I have the following:

from google.appengine.ext import ndb

class User(ndb.Model):
  company = ndb.KeyProperty(repeated=True)

我想拥有的更像是这样:

What I would like to have is something more like this:

class User(ndb.Model):
  company_   = ndb.KeyProperty(repeated=True)

@property
def company(self):
   return '42'

@company.setter
def company(self, new_company):
    #set company here

是否有相对无痛的方法?我希望使用属性获取器/设置器很方便,但是鉴于当前的实现,我希望避免接触基础数据存储.

Is there a relatively pain-free way to do so? I'd like the convienance of using property getter/setters, but given the current implementation I would like to avoid touching the underlying datastore.

推荐答案

据我对ndb的理解,属性名称及其每个实体的内容都存储在数据库中.您将必须使用新的属性名称(而没有旧的属性名称)重写每个实体.

From my understanding of ndb, the property names are stored in the database along with their contents for every entity. You would have to rewrite every entity with the new property name (and without the old one).

由于这并非一帆风顺,所以也许您可以为自己的吸气剂和塞脂剂选择其他名称,例如get_companyset_company.

Since that is not pain-free, maybe you could choose other names for your getter and setter like get_company and set_company.

这篇关于迁移NDB模型属性的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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