Adding a non-null ForeignKey field in Django+South
django, django-south
Solution
You want a data migration to supplement your schema migration in this scenario.
South has a nice step by step tutorial on how to achieve this in the docs, here.
It's not uncommon in South to have the desired outcome spread over two or three schema/data migrations as its not always possible to do it in one big hit (sometimes depends on the underlying db if it will tolerate adding a non null column with no default). So in this case you might add a schema migration that has a default, then a data migration with your object manipulation then a final schema migration.
Problem
I use Django and South for my database. Now I want to add a new Model and a field in an existing model, referencing the new model. For example: ``` class NewModel(models.Model): # a new model # ... class ExistingModel(models.Model): # ... existing fields new_field = models.ForeignKey(NewModel) # adding this now ``` Now South obviously complains that I added a non-null field and asks me to enter a one-off value. But what I really want is to create a new `NewModel` instance for every existing `ExistingModel` instance, thus fulfilling the database requirements. Is that possible somehow?