deschler / django-modeltranslation

Translates Django models using a registration approach.
BSD 3-Clause "New" or "Revised" License
1.34k stars 257 forks source link

sync_translation_fields vs makemigrations #717

Closed gwanghyeongim closed 5 months ago

gwanghyeongim commented 5 months ago

Environments django 4.2 python 3.11 django-modeltranslation 0.18.11

Problems After I register models and fields in translation.py, I ran sync_translation_fields. It created field_en, field_ko in the corresponding models. When I run makemigrations to apply other changes in model, I see field_en, field_ko fields, which already were added by sync_translation_fields, appear in migration files.

$ python manage.py makemigrations --dry-run
Migrations for 'common':
  common/migrations/0037_departport_name_en_departport_name_ko.py
    - Add field name_en to departport
    - Add field name_ko to departport
Migrations for 'company':
  company/migrations/0088_department_name_en_department_name_ko.py
    - Add field name_en to department
    - Add field name_ko to department

This is somewhat confusing. The doc says I should run sync_translation_fields command to apply translatable fields to which language suffix is put.

you should use the sync_translation_fields command. Although it’s possible to introduce new fields in a migration, it’s nasty and involves copying migration files, using MIGRATION_MODULES setting, so we don’t recommend it. Invoking sync_translation_fields is plain easier.

Translation changes are already reflected by the command, so in my understanding there shouldn't be new migration files, which happen.

Am I missing something?

last-partizan commented 5 months ago

Hi

If you're using migrations, you don't need sync_translation_fields.

(If you want to improve docs and make this more clear, PR is welcome).