Q:

Google App Engine Projection Query

I have a model like this:
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

When I tried to make a query like this:
user = db.GqlQuery("SELECT email, api_key, active FROM Users WHERE user_name = :1", username).get()

It's returning None, but when I use this query:
user = db.GqlQuery("SELECT * FROM Users WHERE user_name = :1", username).get()

It's ok, returns everything. But why I can't use the first query?

A:

You cannot project unindexed properties. As stated in the 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.

You can find out what indexes are required by running your query in the Datastore Viewer in the Admin Console.

