GAE python NDB projection query working in development but not in production

馋奶兔 提交于 2019-12-09 04:13:30

I figured it out. Darn it wasn't intuitive at all. I wish GAE documentation was better on this point...

My datastore in production contains a lot of previously created entries. As part of my latest code where I'm trying to do the projection on Entry.payee, I had to change the definition of Entry.payee from unindexed to indexed, like so:

payee = ndb.StringProperty(indexed=True, required=True) # Originally was indexed=False

So now all those entries sitting in the datastore are being ignored by the projection query because the index on payee ignores those entries.

So what I need to do now is somehow migrate all those old entities to be indexed=True.


Update - here's how I did this migration. Turned out simpler than expected.

def runPayeeTypeMigration(exp_traq_name):
  Entry.query(ancestor=exp_traq_key(exp_traq_name)).fetch()
  for entry in entries:
    entry.put()

This works by reading all entries into the updated datastructure (the one where Entry.payee is indexed=True) and writes it back to the datastore, so that the entity will now be indexed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!