coderholic / django-cities

Countries and cities of the world for Django projects
MIT License
913 stars 377 forks source link

Missing migration generated by Django 4 #234

Closed RafaPinzon93 closed 1 year ago

RafaPinzon93 commented 1 year ago

Checklist

Steps to reproduce

When using Django >= 4, makemigrations generates a new migration, and our CI fails when checking pending migrations makemigrations --check

# Generated by Django 4.1 on 2022-11-20 12:17

from django.conf import settings
from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('cities', '0011_auto_20180108_0706'),
    ]

    operations = [
        migrations.AlterField(
            model_name='country',
            name='neighbours',
            field=models.ManyToManyField(to=settings.CITIES_COUNTRY_MODEL),
        ),
    ]

Proposed solutions

Django 4 made a change on the migration autodetector and generates no-op migration for some models: https://docs.djangoproject.com/en/4.1/releases/4.0/#migrations-autodetector-changes

  1. We could add this migration, but the issue with this is that those using Django < 4 will generate a new migration again.
  2. Add one no-op migration that will work for both versions, adding the related_name in neighbours = models.ManyToManyField("self", related_name='_cities_country_neighbours_+' This way it won't check for new migration in both Django versions.

Let me know which is the preferred way and if I can help.