當我嘗試運行日期我收到以下錯誤下令數據存儲查詢:查詢GAE數據存儲時如何解決索引錯誤?
NeedIndexError: no matching index found.
The suggested index for this query is:
- kind: Message
properties:
- name: author
- name: ref
- name: date
查詢運行沒有錯誤,如果我不嘗試通過日期命令。數據存儲區索引下的appengine控制檯說:
author ▲ , ref ▲ , date ▼
Serving
我在做什麼錯?我如何運行按日期排序的查詢?謝謝!
這裏是我的實體定義:
from google.appengine.ext import ndb
class Message(ndb.Model):
subject = ndb.StringProperty()
body = ndb.TextProperty()
date = ndb.DateTimeProperty(auto_now_add=True)
ref = ndb.StringProperty(required=True)
author = ndb.KeyProperty(required=True)
,這是失敗的查詢:
def readMessages(ref, user = None):
query = Message.query()
query = query.filter(Message.ref == ref)
if user:
query = query.filter(Message.author == user.key)
query = query.order(Message.date)
# convert to a list so we can index like an array
return [ message for message in query ]
我index.yaml中包含:
indexes:
- kind: Message
properties:
- name: author
- name: ref
- name: date
direction: desc
謝謝。其實,我忘了複製索引定義的最後一行。應用引擎控制檯指示索引已創建爲參考▲,作者▲,日期▼。所以我不認爲這是我的問題,但我已經更新了問題中的索引定義。 – deltanine 2013-04-22 03:07:27