Did you do any database migrations, or just add the new field? 

Just adding the new field to the model doesn't undo the groundwork laid by your 
original syncdb, which has set up the other field as the primary key in the 
database itself. Although your Django model is the way you want it, your 
database almost certainly is not.

http://south.aeracode.org/

South should help you do what you want. You'll probably need to do it in 
multiple steps. I've not had to switch around primary keys in a Django project 
yet, so hopefully someone else will weigh in on this. But it'll look something 
like the following:

1. Add the new auto-number field in a schema migration (leave out "primary key" 
bit for now). 
2. Remove "primary key" from the old field and add it to the new field, and 
create another schema migration from this.
3. Delete the old field (if desired) from the model and run another schema 
migration.

All this is assuming that no other models have a foreign key reference to this 
model -- that will require a lot more work.

If all else fails, you could create a whole new model, create a data migration 
with South to transfer all the data from the old model, then delete the old 
model. Hopefully you can get by without doing that, but if your production 
database is in an uncertain state then it may be safer.

Shawn


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to