#32697: Older versions of Django insist on converting BigAutoField back to
AutoField
---------------------------------------------+------------------------
               Reporter:  Alexander Todorov  |          Owner:  nobody
                   Type:  Bug                |         Status:  new
              Component:  Migrations         |        Version:  3.2
               Severity:  Normal             |       Keywords:
           Triage Stage:  Unreviewed         |      Has patch:  0
    Needs documentation:  0                  |    Needs tests:  0
Patch needs improvement:  0                  |  Easy pickings:  0
                  UI/UX:  0                  |
---------------------------------------------+------------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32697>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.f7186cb0c2fc0b978d3d080f7fe052bf%40djangoproject.com.

Reply via email to