GAE数据存储使用Python过滤不返回任何数据

GAE数据存储使用Python过滤不返回任何数据,python,google-app-engine,google-cloud-datastore,Python,Google App Engine,Google Cloud Datastore,db模式文件在db/d.py文件中定义如下: from google.appengine.ext import db class D(db.Model): did = db.StringProperty(required = True) sample_tm = db.DateTimeProperty(auto_now_add = True) weekday = db.IntegerProperty(required = False) 并且已经有很多数据插入到了这个模式的

db模式文件在
db/d.py
文件中定义如下:

from google.appengine.ext import db
class D(db.Model):
    did = db.StringProperty(required = True)
    sample_tm = db.DateTimeProperty(auto_now_add = True)
    weekday = db.IntegerProperty(required = False)
并且已经有很多数据插入到了这个模式的数据存储中,正如我在AppEngine的数据存储查看器中看到的那样

然而,当我试图使用python查询处理程序python脚本中的数据时,出现了问题

from db import d
class WaitTimeQuery(webapp2.RequestHandler):

    def post(self):
        self.response.headers['Content-Type'] = 'text/html'         
        q = d.D.all()
        print q.get()
每次它只打印一个
None
。为什么不能以这种方式获取这些数据

我还尝试在python中使用嵌入式gql,但在执行时,它同样不会返回任何结果:

从D中选择*


在data viewer中,结果可以正确显示,如Remco Haszing所说,在编写新应用程序时,首先使用
ndb
而不是
db
。编写遗留应用程序时,可以使用
db
,但您应该迁移到
ndb
;-)

required=False也不是必需的,这是默认值。;-)

创建实例并将其放入:

d = D(did='spam')
d_key = d.put()  # Stores the instance.
d_键
是可用于从数据存储中获取实例的

当您有可能进行查找而不是查询时:

d = d_key.get()
assert d.did == 'spam'
全局查询(
D.query()
)的问题是,没有保险,结果会出现。有关详细信息,请参阅

NDB按步骤写入数据:

  • 在提交阶段,底层数据存储服务记录更改
  • NDB使受影响实体的缓存失效。因此,将来的读取将从底层数据存储中读取(并缓存),而不是从缓存中读取过时的值
  • 最后,可能几秒钟后,底层数据存储应用了更改。它使更改对全局查询可见,并最终实现一致读取
在数据存储中应用更改后,可以使用全局查询:

results = D.query().fetch()  # results will be a list with D instances

使用google.appengine.ext.ndb代替db。也可以使用D.query().fetch()而不是D.all().get()@remcohassing感谢您的回复,尽管它不起作用。返回空列表实体是否有祖先?如果是这样,您需要在查询函数中指定一个
D.query(祖先=我的祖先密钥)。fetch()
results = D.query().fetch()  # results will be a list with D instances