jazzband / django-invitations

Generic invitations app for Django
GNU General Public License v3.0
559 stars 166 forks source link

Extraneous migrations are generated when settings.DEFAULT_AUTO_FIELD is set to BigAutoField #224

Open knyghty opened 1 year ago

knyghty commented 1 year ago

Related to these changes: https://docs.djangoproject.com/en/4.2/releases/3.2/#customizing-type-of-auto-created-primary-keys

This makes it difficult for example to have a CI step to check for missing migrations, as this package is always generating a migration file.

This can be fixed by setting default_auto_field for the models in the project, and making a migration for them if necessary.

mdrie commented 1 year ago

Is there a work-around for this? Is it possible to put the missing migration into my project?

knyghty commented 1 year ago

Is there a work-around for this? Is it possible to put the missing migration into my project?

Not really, no. it needs to be fixed in this repo.

valberg commented 1 year ago

Hi @knyghty

Can you provide me with more info? Especially what the content of the migration file being generated is.

We already have the apps.Config.default_auto_field set to BigAutoField, and I'm not sure what you mean by "setting default_auto_field for the models in the project".

knyghty commented 1 year ago

Hi @valberg,

The problem, as I understand it (which is somewhat, but not fully), is that there is currently the initial migration that uses AutoField: https://github.com/jazzband/django-invitations/blob/master/invitations/migrations/0001_initial.py#L17

Because this is generated from the implicit id field, i.e. it isn't specified explicitly in the Invitation model, Django now wants to generate this migration, which should be added to the project:

from django.db import migrations, models

class Migration(migrations.Migration):
    dependencies = [
        ("invitations", "0003_auto_20151126_1523"),
    ]

    operations = [
        migrations.AlterField(
            model_name="invitation",
            name="id",
            field=models.BigAutoField(
                auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
            ),
        ),
    ]
knyghty commented 1 year ago

Ah, I now see that this has already been done, just not released, so sorry for the noise here. A release would be appreciated, though, if someone has the time to prep it.