3

I have updated a model of which some instance have already been stored in the datastore. I deleted some of its properties.
Is is possible to fully delete those properties from the datastore?
(I don't mean setting it to None)

Remco Haszing
  • 7,178
  • 4
  • 40
  • 83

2 Answers2

4

After changing your model, newer rows added will not have the column. Existing rows will continue to have the column. You should be able to run an update on the existing data to remove that column using the article given below.

Docs article: https://developers.google.com/appengine/articles/update_schema

abel
  • 2,377
  • 9
  • 39
  • 62
1

The article in @abel's answer includes some important adjacent concepts, but isn't all that clear on how to actually remove a column. (There's some high-level description, and no code example.)

The strategy in the answer here worked for me: https://stackoverflow.com/a/12701172/7470370

A more complete example...

from google.appengine.ext import ndb

class Model_1(ndb.Model):
    propToKeep = ndb.StringProperty()
    propToDelete = ndb.StringProperty()

entities = Model_1.query().fetch() # get all records
    for entity in entities:
        if 'propToDelete' in entity._properties:
            del entity._properties['propToDelete']
            entity.put()