views:

54

answers:

1

I have a legacy database with an integer set as a primary key. It was initially managed manually, but since we are wanting to move to django, the admin tool seemed to be the right place to start. I created the model and am trying to set the primary key to be an autofield. It doesn't seem to be remembering the old id in updates, and it doesn't create new id's on insert. What am I doing wrong?

+2  A: 

The DB is responsible for managing the value of the ID. If you want to use AutoField, you have to change the column in the DB to use that. Django is not responsible for managing the generated ID

Mohammad Tayseer
In fact, Django will not modify a table in a database that already exists. You will have to manually do 'manage.py dbshell' and add in the required index on the database. How to do this will probably be database dependant.
Matthew Schinckel