Home > database >  django-registration-redux and spurious migration from DEFAULT_AUTO_FIELD of BigAutoField
django-registration-redux and spurious migration from DEFAULT_AUTO_FIELD of BigAutoField

Time:02-05

I installed django-registration-redux 2.11 into Django 4.1.6.

When I run makemigrations, it makes a migration to change an id field to BigAutoField:

# Generated by Django 4.1.6 on 2023-02-03 19:33

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("registration", "0005_activation_key_sha256"),
    ]

    operations = [
        migrations.AlterField(
            model_name="registrationprofile",
            name="id",
            field=models.BigAutoField(
                auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
            ),
        ),
    ]

I suspect this is because DEFAULT_AUTO_FIELD is now BigAutoField as of Django 3.2, see here.

However, it's creating a migration in my virtualenv, not under source code control:

$ ./manage.py makemigrations
Migrations for 'registration':
  .venv/lib/python3.10/site-packages/registration/migrations/0006_alter_registrationprofile_id.py
    - Alter field id on registrationprofile

So that's not gonna work well.

I don't want to change my DEFAULT_AUTO_FIELD to AutoField. I just want to change it for django-registration-redux I guess?

I see that registration already has default_auto_field = 'django.db.models.AutoField', so I'm puzzled as to why Django is making this migration.

I tried adding my own registration/apps.py into source code control with default_auto_field as AutoField, and that didn't work.

Suggestions?

I might just have to move to django-allauth or back to django-registration, as they suggest.

CodePudding user response:

I see that registration already has default_auto_field = 'django.db.models.AutoField', so I'm puzzled as to why Django is making this migration.

The reason default_auto_field will likely not work is because it is defined on the model, not the app config.

I tried adding my own registration/apps.py into source code control with default_auto_field as AutoField, and that didn't work.

This will work… on your registration app, so the models defined in that app, not in other apps.

Likely the best way to fix this is to fix it on the package itself, by specifying an AppConfig that then defines, for the scope of that package, the default_auto_field. I submitted a pull request (#431) [GitHub] for this.

  • Related