使用Google App Engine和ndb时,是否会看到重复的ID? [英] Ever see duplicate IDs when using Google App Engine and ndb?

查看:192
本文介绍了使用Google App Engine和ndb时,是否会看到重复的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  class Entries(ndb.Model):
description = ndb.StringProperty()
seqid = ndb.InteProProperty()
link = ndb.StringProperty()
group = ndb.StringProperty()
timestamp = ndb.StringProperty()
referrals = ndb.StringProperty(repeated = True)

图片中的两个条目由两个不同的用户创建。用户是Entry的父项。



我在产品上得到重复的ID,但不在本地。此外,它始终是相同的ID号码(但它肯定不是硬编码的任何地方)。

由于父母是用户,我仍然可以将其作为唯一条目这意味着如果我有两个条目与同一个父级用户,就会出现问题。

解决方案

数据存储区的唯一密钥是完全合格的密钥,包括所有的父实体密钥,而不仅仅是ID。具有相同ID和不同父母的多个实体是完全有效的,并且您不应仅依赖于唯一的id。


class Entries(ndb.Model):
  description = ndb.StringProperty()
  seqid = ndb.IntegerProperty()
  link = ndb.StringProperty()
  group = ndb.StringProperty()
  timestamp = ndb.StringProperty()
  referrals = ndb.StringProperty(repeated=True)

The two entries in the picture are created by two different users. The user is the parent of the Entry.

I get a duplicate ID on production but not on local. Also, it's always this same id number (but it is certainly not hard coded anywhere)

As the parent is the user, i can still pull it as a unique entry but it will mean there will be problems if I have two entries with the same parent user.

解决方案

A datastore's unique key is the fully qualified key, including all parent entity keys, not just the ID. Multiple entities with the same ID and different parents are completely valid, and you shouldn't rely on the id alone being unique.

这篇关于使用Google App Engine和ndb时,是否会看到重复的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆