Search code examples
djangodjango-south

django south - unique=True, but "give default value for existing rows" ?


I have created an index field

channel_indexid = PositiveIntegerField(db_index=True, unique=True)

If I try to migrate, south is asking me to enter default value for existing rows.

1. Quit now, and add a default...
2. Specify a one-off value.. 

But, channel_indexid is a unique, how can I give one default value for all rows? is there any workound for this. this is really annoying


Solution

  • Since you are modifying a model, South will ask you for default value for existing rows since your new field, by default is null=False. You can avoid to give it a default value by setting null=True, blank=True.

    If you don't want it to be nullable and you still want to add this field as not nullable, then you have to drop the table and create it again with your new field.

    South by default give new columns a null value but since by default fields are null=False then South ask you for a value to give to the new field. South does not give empty strings or 0 as default values for string or integer fields, you have to tell South the default value if the field is not nullable, and if it is nullable it will give a default value of null.