psun
psun

Reputation: 635

Google App Engine Updating schema in DB model

I'm adding new attribute to an existing data store model. I need to update an existing schema with data to the new schema. I have checked google's doc on updating schema and it uses ndb model.

I have a DB model like this:

class oldModel(db.Model):
     name = db.StringProperty(default = "")
     author = db.StringProperty(default = "")
     created = db.DateTimeProperty(auto_now_add = True)

My new new schema is:

class oldModel(db.Model):
     name = db.StringProperty(default = "")
     author = db.StringProperty(default = "")
     created = db.DateTimeProperty(auto_now_add = True)
     # new field
     category = db.IntegerProperty(default = 0)  

How do you do it? (One thing I think of is to include the new schema with a different name and manually populate the data from old one to new schema and drop the old one)

Upvotes: 0

Views: 46

Answers (1)

minou
minou

Reputation: 16563

It is really easy to add a property. Just add it to your model. For any entities that existed before, they will have the default value. If your previously existing entities need to have a different value for the new property, then you will have to iterate over them and set the new property to the desired value.

Upvotes: 2

Related Questions