I had a Django model that looked like the following:
class Foobar(models.Model):
baz = models.CharField(max_length=12, default=some_func)
some_func
existed in a file /someproj/utils/utils.py
This was fine, and all was well. I created my migration for this model and worked as expected. Roughly the migration looked like:
from __future__ import unicode_literals
from django.db import migrations, models
import someproj.utils.utils
class Migration(migrations.Migration):
dependencies = [("someproj", "0008_auto_20180928_0002")]
operations = [
migrations.CreateModel(
name="Foobar",
fields=[
(
"baz",
models.CharField(
default=someproj.utils.utils.some_func,
max_length=12,
serialize=False,
),
),
],
)
]
Then I later realized I wanted to rename some_func
to something else. I renamed the function in utils.py, and of course now the migration fails as some_func no longer exists. If I modify the migration by hand that works, but the rule of thumb that was explained to me is you (almost) never edit a migration by hand.
What is a way to accommodate this change? Is it you have to edit the migration by hand? Wouldn't that be problematic if I had to run an older version of the code (ie say I had to checkout a previous commit to a point in time before the rename)?