Search code examples
djangomodeldefaultdjango-southdatabase-migration

propagate new default value to old Django objects


I just added a default value to one of the fields of one of the models in my Django site. All objects of this type that existed before I set the default have a null value for this field. I would like the new default value that I just set to be propagated backwards onto all of the objects that already existed before I set the default value. How can I do this?


Solution

  • Just run an update query:

    MyModel.objects.filter(myfield__isnull=True).update(myfield=new_value)