Lagerregal icon indicating copy to clipboard operation
Lagerregal copied to clipboard

Inconsistent makemigrations results

Open xi opened this issue 7 years ago • 2 comments

When running manage.py makemigrations on different setups, I get different results.

xi avatar Jun 19 '18 15:06 xi

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=None is removed from devices.models.Device.used_in
  • There are some changes connected to unicode, even in #223. For example the choices for users.models.Lageruser.timezone are from pytz.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.

xi avatar Jun 20 '18 11:06 xi

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:

  1. live with it
  2. 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))
  3. Move the choices to the form (I tried this and failed)

xi avatar Apr 19 '21 10:04 xi