AppEngine - Weird ID assignment in AppEngine HR DataStore [duplicate]
Possible Duplicate:
How to implement “autoincrement” on Google AppEngine
I've got a Python App in AppEngine. I'm using High Replication Datastore.
This is my problem:
I have an entity (call it Person for simplicity) that is saved without parents, it's a root entity in the AppEngine terms.
I don't set a key_name before save my entities, becouse i want the numeric IDs assigned by the DataStore. Some Code:
p = Person(name='Juan Roman Riquelme')
p.put()
p.key().id() # the numeric ID
The problem is that the IDs are not consecutive. Every time i update my app (appcfg.py update .) the ids start in the next thousands. I mean, the first time i update my app, the IDs where 1,2,3,etc. The next time were: 1001,1002,1003, etc. The thirth: 2001,2002, etc.
What's going on? What should i do to keep them consecutive?
Thanks!
Why do you need them to be consecutive?
App Engine datastore doesn't assign IDs to be consecutive.
If you want consecutive IDs, you must assign IDs yourself. Don't forget to use allocate_id_range (http://code.google.com/appengine/docs/python/datastore/functions.html) so that app engine doesn't automatically assign already-existing IDs.
精彩评论