How to update a model

Suppose I have a model definition as follows:

class Image(db.Model):
    id = db.StringProperty()
    url = db.URLProperty()

Now I want to add some fields to this model so that they look like this:

class Image(db.Model):
    id = db.StringProperty()
    url = db.URLProperty()
    width = db.IntegerProperty()
    height = db.IntegerProperty()

So, this new model will be correctly applied to newly added objects Image. But I also want to update the existing objects so that they contain these two new fields and fill them with values. Will an existing object automatically receive these two fields, so when I access them, will it give me empty fields or will it cause an error? I suppose I will have to create a helper function that will go through all existing entities and set new field values, right? So what should I keep in mind and how best to do this model update? I think this will happen sometimes as the application arrives, so I think it would be useful to have some simple thread for this.

+3
source share
2 answers

GAE ( ):

.

, , . - .

+3

None. . - remote_apy script . , script, .

+2

All Articles