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

查看:25
本文介绍了迁移 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

有没有相对无痛的方法呢?我想要使​​用属性 getter/setter 的便利性,但鉴于当前的实现,我想避免接触底层数据存储.

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).

由于这不是无痛的,也许您可​​以为您的 getter 和 setter 选择其他名称,例如 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天全站免登陆