1

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!

Community
  • 1
  • 1
santiagobasulto
  • 11,320
  • 11
  • 64
  • 88
  • 1
    Take a look at [this](http://stackoverflow.com/questions/3985812/how-to-implement-autoincrement-on-google-appengine) question. – Kevin P Jun 23 '11 at 16:42
  • Thanks Kevin. It's really useful. – santiagobasulto Jun 23 '11 at 19:44
  • IT WAS NOT A DUPLICATE! I hate this guys. I was not asking how to implement Autoincrement I DON'T CARE HOW TO IMPLEMENT AUTOINCREMENT. I wanted to know how to fix that thing in AppEngine Administration. You love to close things just to feel important? – santiagobasulto Jun 24 '11 at 10:44
  • You're asking how to create IDs that always increment. If that's different from autoincrement, you'll have to explain how. – Nick Johnson Jun 24 '11 at 13:29
  • @Nick I was looking some way to "fix" the "datastore interval steps". Actually the AutoIncrement was useful to me, but for other things. Maybe i didn't explain myself correctly. My english isn't that good. After some research i found impossible to make the DataStore not to do those 1000 ids steps. Thanks for your help Nick. – santiagobasulto Jun 24 '11 at 13:47

1 Answers1

3

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.

Andz
  • 2,228
  • 19
  • 13
  • I need them consecutive. I'll take a look to that. Thank you! – santiagobasulto Jun 23 '11 at 19:35
  • @santiagobasulto Why do you need them consecutive? That's rarely actually the case, and attempting to do so is inherently unscalable - you're letting yourself in for a mess of problems if you try. – Nick Johnson Jun 24 '11 at 00:51
  • @Nick. Yes, you're right nick. I'm doing a URLShortener, and it works mapping ids to an alphabet (aprox 59 chars). It would be good to have the ids consecutive just to not waste "combinations of chars". I'm thinking other ways to do it. I was just thinking in the MySQL way. I'm in the cloud now! Thank you for your interest. – santiagobasulto Jun 24 '11 at 10:46