简体   繁体   中英

Why does this fail? (google appengine datastore, python)

  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'

The table 'Store' exists.

the error is:

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'

You need to define a model for "Store". Even if you've managed to get data into the datastore as Store rows, this fails when the model class doesn't exist.

I verified this by renaming one of my model classes in a working application that had data stored for that type of object. It throws the same exception, so I'm guessing that's the cause of your problem too. Add this somewhere in your application, and see if it changes the error:

class Store(db.Model):
    pass

Also, this isn't causing the error, but count is actually a method. You should use this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM