Inconsistent makemigrations results
When running manage.py makemigrations on different setups, I get different results.
In django/db/migrations/autodetector.py line 912 (in generate_altered_fields() directly after if old_field_dec != new_field_dec:) I added the following code for debugging:
print(app_label, model_name, field_name)
print(old_field_dec)
print(new_field_dec)
print()
Then I ran ./manage.py makemigrations --dry-run with different setups. This is what I found so far:
- I did not find differences between py35 and py36.
- In both py2 and py3
default=Noneis removed fromdevices.models.Device.used_in - There are some changes connected to unicode, even in #223. For example the choices for
users.models.Lageruser.timezoneare frompytz.common_timezones. Depending on the python version these are either unicode or byte strings. - Sometimes choices are derived from dictionaries. As the ordering of dictionaries is not guaranteed in python, there can be unintended changes.
We can still have this issue because some model choices depend on settings (e.g. Lageruser.theme) or external libraries (e.g. Lageruser.timezone). I am not sure what to do about that. There was some talk in django about that a while ago (see https://code.djangoproject.com/ticket/22837) but nothing came of it.
I see some options:
- live with it
- ignore choices in migrations as they have no real impact on the database (e.g. with django-migrations-ignore-attrs (does not look like a mature project on first glance))
- Move the choices to the form (I tried this and failed)