python – Google App Engine投影查询

我有这样的模型:

class Users(db.Model):
   email = db.EmailProperty(required=True, indexed=True)
   user_name = db.StringProperty(required=True, indexed=True)
   api_key = db.StringProperty(required=False, indexed=False)
   active = db.BooleanProperty(required=True, indexed=False)
   real_name = db.StringProperty(required=False, indexed=False)
   ...etc

当我尝试进行这样的查询时:

user = db.GqlQuery("SELECT email, api_key, active FROM Users WHERE user_name = :1", username).get()

它返回None,但是当我使用这个查询时:

user = db.GqlQuery("SELECT * FROM Users WHERE user_name = :1", username).get()

没关系,退货.但为什么我不能使用第一个查询?

最佳答案 您无法投影未编入索引的属性.如
documentation所述

There are some limitations on what properties can be projected:
You can only project indexed properties. This means that projecting Text, Blob or other properties explicitly marked as unindexed is not supported.

您可以在管理控制台的数据存储查看器中查找运行查询所需的索引.

点赞