2011-03-19 103 views
2
1 from google.appengine.ext import webapp 
    2 from google.appengine.ext.webapp.util import run_wsgi_app 
    3 from google.appengine.ext import db 
    4 
    5 a = db.GqlQuery('SELECT * FROM Store WHERE count = True').count 
    6 
    7 print 'Content-Type: text/plain' 
    8 print '' 
    9 print str(a)+'blah blah' 

表'存儲'存在。這爲什麼會失敗? (谷歌appengine數據存儲,蟒蛇)

的錯誤是:

Traceback (most recent call last): 
    File "/opt/google-appengine/google/appengine/tools/dev_appserver.py", line 3245, in _HandleRequest 
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict) 
    File "/opt/google-appengine/google/appengine/tools/dev_appserver.py", line 3186, in _Dispatch 
    base_env_dict=env_dict) 
    File "/opt/google-appengine/google/appengine/tools/dev_appserver.py", line 531, in Dispatch 
    base_env_dict=base_env_dict) 
    File "/opt/google-appengine/google/appengine/tools/dev_appserver.py", line 2410, in Dispatch 
    self._module_dict) 
    File "/opt/google-appengine/google/appengine/tools/dev_appserver.py", line 2320, in ExecuteCGI 
    reset_modules = exec_script(handler_path, cgi_path, hook) 
    File "/opt/google-appengine/google/appengine/tools/dev_appserver.py", line 2216, in ExecuteOrImportScript 
    exec module_code in script_module.__dict__ 
    File "/home/jck/bitsconv/bitsconv.py", line 5, in <module> 
    a = db.GqlQuery('SELECT * FROM Store WHERE count = True').count() 
    File "/opt/google-appengine/google/appengine/ext/db/__init__.py", line 2298, in __init__ 
    model_class = class_for_kind(self._proto_query._entity) 
    File "/opt/google-appengine/google/appengine/ext/db/__init__.py", line 266, in class_for_kind 
    raise KindError('No implementation for kind \'%s\'' % kind) 
KindError: No implementation for kind 'Store' 

回答

6

您需要定義一個模型 「商店」。即使您設法以Store行的形式將數據存入數據存儲區,當模型類不存在時,也會失敗。

我通過在工作應用程序中重新命名我的一個模型類來驗證這一點,該工作應用程序爲該類型的對象存儲了數據。它引發同樣的異常,所以我猜這也是你的問題的原因。增加這個地方在你的應用程序,看它是否改變了錯誤:

class Store(db.Model): 
    pass 

而且,這不是導致錯誤,但count實際上是一個方法。你應該使用這個:

a = db.GqlQuery('SELECT * FROM Store WHERE count = True').count() 
+0

謝謝,工作! – jck 2011-03-19 23:18:09

+0

@jck:具體地說,「表存儲存在」不是真的;沒有表格,只是實體。 – geoffspear 2011-03-20 03:58:14