#35761: When switching which field is `primary_key`, migrations do not seem to
handle multiple `auto` columns
-------------------------------------+-------------------------------------
     Reporter:  Jonas Vacek          |                    Owner:  (none)
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  migrations, PK,      |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Jonas Vacek):

 My workaround for this was to Swap operations 3 and 4, and change the
 order of the alter tables in the primary key addition

 {{{
     operations: list[Operation] = [
         migrations.AlterField(
             model_name="lookeruser",
             name="user",
             field=models.OneToOneField(
                 help_text="The user on our platform.",
                 on_delete=django.db.models.deletion.CASCADE,
                 related_name="looker_user",
                 to=settings.AUTH_USER_MODEL,
             ),
         ),
         migrations.RunSQL(
             sql="""
                 ALTER TABLE `custom_reporting_lookeruser` ADD CONSTRAINT
 `custom_reporting_lookeruser_id_14e613d0_pk` PRIMARY KEY (`id`);
                 ALTER TABLE `custom_reporting_lookeruser` MODIFY `id`
 bigint AUTO_INCREMENT NOT NULL;
                 """,
             state_operations=[
                 migrations.AlterField(
                     model_name="lookeruser",
                     name="id",
                     field=models.BigAutoField(auto_created=True,
 primary_key=True, serialize=False, verbose_name="ID"),
                 ),
             ],
         ),
     ]

 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35761#comment:2>
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/01070191ec0eed6a-fd7413cb-5551-4c5c-83df-92c3b6a1d010-000000%40eu-central-1.amazonses.com.

Reply via email to