Which I tried to change to
{{{
#!div style="font-size: 80%"
{{{#!python
class AbstractOwnershipModel(models.Model):
owner_user= models.ForeignKey('auth.User',db_index=True)
class Meta:
abstract = True
}}}
}}}
But makemigrations reports that there are no changes even though I would
expect a bunch of indexes to be created.
--
Ticket URL: <https://code.djangoproject.com/ticket/33947>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> I have a bunch of Models of the form
> {{{
> #!div style="font-size: 80%"
> {{{#!python
> class AbstractOwnershipModel(models.Model):
> owner_user= models.ForeignKey('auth.User')
> class Meta:
> abstract = True
> }}}
> }}}
>
> Which I tried to change to
> {{{
> #!div style="font-size: 80%"
> {{{#!python
> class AbstractOwnershipModel(models.Model):
> owner_user= models.ForeignKey('auth.User',db_index=True)
> class Meta:
> abstract = True
> }}}
> }}}
>
> But makemigrations reports that there are no changes even though I would
> expect a bunch of indexes to be created.
New description:
I have a bunch of Models of the form
{{{
#!div style="font-size: 80%"
{{{#!python
class AbstractOwnershipModel(models.Model):
owner_user= models.ForeignKey('auth.User')
class Meta:
abstract = True
class AnOwnedModel(AbstractOwnershipModel):
#...
}}}
}}}
Which I tried to change to
{{{
#!div style="font-size: 80%"
{{{#!python
class AbstractOwnershipModel(models.Model):
owner_user= models.ForeignKey('auth.User',db_index=True)
class Meta:
abstract = True
}}}
}}}
But makemigrations reports that there are no changes even though I would
expect a bunch of indexes to be created.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33947#comment:1>
* status: new => closed
* resolution: => invalid
Comment:
>But makemigrations reports that there are no changes even though I would
expect a bunch of indexes to be created.
That's because the index is
[https://docs.djangoproject.com/en/4.1/ref/models/fields/#django.db.models.ForeignKey
already created by default]:
>A database index is automatically created on the `ForeignKey`. You can
disable this by setting `db_index` to `False`. You may want to avoid the
overhead of an index if you are creating a foreign key for consistency
rather than joins, or if you will be creating an alternative index like a
partial or multiple column index.
You can check by connecting to the database using `./manage.py dbshell`
and looking at the database schema.
--
Ticket URL: <https://code.djangoproject.com/ticket/33947#comment:2>