Skip to content Skip to sidebar Skip to footer

Proper Way To Migrate Ndb Model Property

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 cla

Solution 1:

you can change the class-level property name while keeping the underlying NDB property name by specifying the name="xx" param in the Property() constructor

so something like this could be done:

classUser(ndb.Model):
  company_   = ndb.KeyProperty(name="company", repeated=True)

  @propertydefcompany(self):
    returnself.company_

  @company.setter
  defcompany(self, new_company):
    self.company_ = new_company

so now anytime you access .company_ NDB will actually set/get "company" internally... and you don't have to do any data migrations

Solution 2:

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

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

Post a Comment for "Proper Way To Migrate Ndb Model Property"