In a comment to this question answer I asked how to remove a field with a default value function. To sum up, the example code is:
def get_deadline():
return datetime.today() + timedelta(days=20)
class Bill(models.Model):
name = models.CharField(max_length=50)
customer = models.ForeignKey(User, related_name='bills')
date = models.DateField(default=datetime.today)
deadline = models.DateField(default=get_deadline)
and my question to the code is:
How do you remove the
deadline
field again while also deleting theget_deadline
function? I have removed a field with a function for a default value, but now Django crashes on startup after removing the function. I could manually edit the migration, which would be ok in this case, but what if you simply changed the default function, and wanted to remove the old function?
I ended up removing the default part of the migration that referred to it, but how do you remove it nicely?
The only way I can think of is to squash the migrations, such that the migration using the function disappears, but that is not always an option.