views:

662

answers:

5

For our Django App, we'd like to get an AutoField to start at a number other than 1. There doesn't seem to be an obvious way to do this. Any ideas?

A: 

A quick peek at the source shows that there doesn't seem to be any option for this, probably because it doesn't always increment by one; it picks the next available key: "An IntegerField that automatically increments according to available IDs" — djangoproject.com

William Keller
+1  A: 

The auto fields depend, to an extent, on the database driver being used.

You'll have to look at the objects actually created for the specific database to see what's happening.

S.Lott
+2  A: 

Like the others have said, this would be much easier to do on the database side than the Django side.

For Postgres, it'd be like so: ALTER SEQUENCE sequence_name RESTART WITH 12345; Look at your own DB engine's docs for how you'd do it there.

AdamKG
+1  A: 

It looks as though Django 1.0 cannot do this automatically and needs to be done on the DB side instead. Maybe in the future Django will do this for the user.

A: 

What is the policy when a given parameter is not supported in a give back-end?