Opened 4 years ago

Closed 4 years ago

#32697 closed Bug (invalid)

Older versions of Django insist on converting BigAutoField back to AutoField

Reported by: Alexander Todorov Owned by: nobody
Component: Migrations Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've added the following change to django-attachments:

 class AttachmentsConfig(AppConfig):
+    default_auto_field = 'django.db.models.BigAutoField'
     name = "attachments"
     verbose_name = _("Attachments")
diff --git a/attachments/migrations/0006_alter_pk_to_BigAutoField.py b/attachments/migrations/0006_alter_pk_to_BigAutoField.py
new file mode 100644
index 0000000..ab840dd
--- /dev/null
+++ b/attachments/migrations/0006_alter_pk_to_BigAutoField.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2 on 2021-04-27 20:18
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('attachments', '0005_object_id_charfield'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='attachment',
+            name='id',
+            field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
+     

Since the release notes point out that in the future BigAutoField is to be the default and that new apps are already generated with BigAutoField I've decided to use that as the default value. The new migration will take care of existing installations. Or so I thought.

In our test suite when running with Django < 3.2 (e.g. 3.1.8) makemigrations insists on reverting this field back to AutoField and it creates the following 3rd migration - attachments/migrations/0007_auto_20210429_0400.py:

# Generated by Django 3.1.8 on 2021-04-29 04:00

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('attachments', '0006_alter_pk_to_BigAutoField'),
    ]

    operations = [
        migrations.AlterField(
            model_name='attachment',
            name='id',
            field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
        ),
    ]

I wasn't able to figure out how to prevent this from happening or what's causing it but I see this as a problem.

For example a downstream app which is using django-attachments will call makemigrations to adjust their own migrations at some point in time, which will result in unwanted (and maybe even undetected) migrations for django-attachments.

Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: invalid
Status: newclosed

Since the release notes point out that in the future BigAutoField is to be the default ...

First of all I would like to ensure you that this will not happen in the nearest future (maybe never). I can not imagine that we would change that before dropping support for all versions prior to 3.2.

In our test suite when running with Django < 3.2 (e.g. 3.1.8) makemigrations insists on reverting this field back to AutoField and it creates the following 3rd migration - attachments/migrations/0007_auto_20210429_0400.py:

That's because AppConfig.default_auto_field doesn't exist in Django < 3.1, so it cannot be taken into account.

I would recommend to keep default_auto_field = 'django.db.models.AutoField' until Django 3.2 becomes the minimal Django supported by your package.

Note: See TracTickets for help on using tickets.
Back to Top