#25317: Altering a field to ForeignKey does not create index
-------------------------------+--------------------------------------
     Reporter:  synotna        |                    Owner:  nobody
         Type:  Bug            |                   Status:  closed
    Component:  Uncategorized  |                  Version:  1.8
     Severity:  Normal         |               Resolution:  invalid
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by synotna):

 Sorry, you are correct: I did not make the connection that the
 OneToOneField should have already created the index beforehand

 Here is the migration that created the model including the OneToOneField,
 and the output from sqlmigrate which shows that index creation was
 missing:


 {{{
         migrations.CreateModel(
             name='ContractTwitchChannelRevenueAdsByCountry',
             fields=[
                 ('id', models.AutoField(primary_key=True, serialize=False,
 auto_created=True, verbose_name='ID')),
                 ('partner_revenue', models.DecimalField(decimal_places=7,
 max_digits=12)),
                 ('contract_twitch_channel',
 models.ForeignKey(to='partners.ContractTwitchChannel')),
                 ('revenue_data',
 models.OneToOneField(to='twitchrevenue.TwitchRevenueDataAdsByCountry')),
             ],
             options={
             },
             bases=(models.Model,),
         ),
 }}}


 {{{
 ./manage.py sqlmigrate partners 0007

 BEGIN;
 CREATE TABLE "partners_contracttwitchchannelrevenueadsbycountry" ("id"
 serial NOT NULL PRIMARY KEY, "partner_revenue" numeric(12, 7) NOT NULL,
 "contract_twitch_channel_id" integer NOT NULL, "revenue_data_id" integer
 NOT NULL UNIQUE);
 ALTER TABLE "partners_contracttwitchchannelrevenueadsbycountry" ADD
 CONSTRAINT "ccbec8ea2680b0e44e335452dd041304" FOREIGN KEY
 ("contract_twitch_channel_id") REFERENCES "partners_contracttwitchchannel"
 ("id") DEFERRABLE INITIALLY DEFERRED;
 ALTER TABLE "partners_contracttwitchchannelrevenueadsbycountry" ADD
 CONSTRAINT "a1dfe1f83ea9a2dbb28dc2ec53ef0136" FOREIGN KEY
 ("revenue_data_id") REFERENCES
 "twitchrevenue_twitchrevenuedataadsbycountry" ("id") DEFERRABLE INITIALLY
 DEFERRED;
 CREATE INDEX "partners_contracttwitchchannelrevenueadsbycountry_71b8390c"
 ON "partners_contracttwitchchannelrevenueadsbycountry"
 ("contract_twitch_channel_id");

 COMMIT;
 }}}

 Am I correct in thinking that is a bug? If so then I'll edit (or open) a
 new bug ticket correctly

--
Ticket URL: <https://code.djangoproject.com/ticket/25317#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/065.2cb13929df96272c1d87ca214209442f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to