#28573: Migrations create a bad index if creating and renaming the same foreign 
key
in one migration
----------------------------------+--------------------------------------
     Reporter:  Jerome Leclanche  |                    Owner:  nobody
         Type:  Uncategorized     |                   Status:  new
    Component:  Migrations        |                  Version:  1.11
     Severity:  Normal            |               Resolution:
     Keywords:                    |             Triage Stage:  Unreviewed
    Has patch:  0                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  0                 |                    UI/UX:  0
----------------------------------+--------------------------------------
Description changed by Tim Graham:

Old description:

> I have the following monster migration:
>
> https://github.com/jleclanche/dj-
> stripe/blob/61ad7e3fa0e0b6a8ead68d892f66fc7d26edefda/djstripe/migrations/0002_card_customer_from_source.py
>
> Putting aside most of it; when running it, I was getting the following
> error:
>
>     django.db.utils.ProgrammingError: column "customer_from_source_id"
> does not exist
>
> That was very confusing, but when debugging it I found out that it's
> choking all the way at the end on the following sql statement:
>
>     CREATE INDEX "djstripe_card_customer_from_source_id_2343e200" ON
> "djstripe_card" ("customer_from_source_id")
>
> Now, that's weird because it shouldn't be creating that index on
> "customer_from_source_id" but on "customer_id" instead. The field is
> first created like so:
>
>         migrations.AddField(
>             model_name="card",
>             name="customer_from_source",
>             field=models.ForeignKey(null=True,
> on_delete=django.db.models.deletion.CASCADE, related_name="sources",
> to="djstripe.Customer"),
>         ),
>
> Then, it is renamed:
>
>         migrations.RenameField(
>             model_name="card",
>             old_name="customer_from_source",
>             new_name="customer",
>         ),

New description:

 I have the following monster migration:

 https://github.com/jleclanche/dj-
 
stripe/blob/61ad7e3fa0e0b6a8ead68d892f66fc7d26edefda/djstripe/migrations/0002_card_customer_from_source.py

 Putting aside most of it; when running it, I was getting the following
 error:
 {{{
     django.db.utils.ProgrammingError: column "customer_from_source_id"
 does not exist
 }}}
 That was very confusing, but when debugging it I found out that it's
 choking all the way at the end on the following sql statement:

     CREATE INDEX "djstripe_card_customer_from_source_id_2343e200" ON
 "djstripe_card" ("customer_from_source_id")

 Now, that's weird because it shouldn't be creating that index on
 "customer_from_source_id" but on "customer_id" instead. The field is first
 created like so:
 {{{
         migrations.AddField(
             model_name="card",
             name="customer_from_source",
             field=models.ForeignKey(null=True,
 on_delete=django.db.models.deletion.CASCADE, related_name="sources",
 to="djstripe.Customer"),
         ),
 }}}
 Then, it is renamed:
 {{{
         migrations.RenameField(
             model_name="card",
             old_name="customer_from_source",
             new_name="customer",
         ),
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28573#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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.b20b8790758876cfd8da1ae74b39b61c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to