On Sat, 2007-03-24 at 18:04 -0700, Mark Engelberg wrote: > I know that, unfortunately, there's no painless way to migrate all the > data in your database when you add a new optional field to your model. > Pity. > > So what is the MOST painless way to do this?
(1) Add the field to your model. (2) Run "manage.py sql <app_name>" and note the type of column that is added to the model's table. (3) At your database prompt ("manage.py shell" and go from there), execute "ALTER TABLE ADD COLUMN ... DEFAULT ...", filling in the first "..." part with the column definition you noted before. You will also need to add a DEFAULT value to the column at the database level so that existing entries have a value for that column. If the column can be NULL, you won't need the default value -- it will just put NULLs in there for all the existing entries. (4) Sit back with drink of choice and realise just how painless the whole process was. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---