[Django] #26889: Index creation different if SlugField in CreateModel or in AddField of a migration on postgresql

46 views
Skip to first unread message

Django

unread,
Jul 12, 2016, 5:01:06 AM7/12/16
to django-...@googlegroups.com
#26889: Index creation different if SlugField in CreateModel or in AddField of a
migration on postgresql
-------------------------+-------------------------------------------------
Reporter: | Owner: nobody
aRkadeFR |
Type: Bug | Status: new
Component: | Version: 1.9
Migrations | Keywords: migrations, index, postgresql,
Severity: Normal | slugfield
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------------------
Hello,

I've run into a different index creation behavior of the `django migrate`
command if a `SlugField` of a `Model` is created in the `CreateModel`
method in a migration or in a `AddField` method.


If we have a model like so:
{{{
from django.db import models


class TestModel(models.Model):
""" DocString for the class """
value = models.IntegerField('value of the model')
slug_model = models.SlugField()
}}}


If we leave the slug_models creation in the CreateModel method of the
migration, an index `testt_models_testmodel_slug_model_f9e19be9_like` is
created
{{{
# the index
"testt_models_testmodel_slug_model_f9e19be9_like" btree (slug_model
varchar_pattern_ops)

# the migration
migrations.CreateModel(
name='TestModel',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True,
serialize=False, verbose_name='ID')),
('value', models.IntegerField(verbose_name='value of the model')),
('slug_model', models.SlugField()),
],
),
}}}

Now if we create the slug_field with a CreateField method in the
migrations, we don't have the index (that happen if it's actually a
migration after the 0001_initial of an app).
{{{
# migration
migrations.CreateModel(
name='TestModel',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True,
serialize=False, verbose_name='ID')),
('value', models.IntegerField(verbose_name='value of the model')),
],
),
migrations.AddField(
model_name='testmodel',
name='slug_model',
field=models.SlugField(),
),
}}}

I would expect either django-migrations to not create index, or have
consistent schema output between the two methods.

Thanks

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

Django

unread,
Jul 12, 2016, 1:59:30 PM7/12/16
to django-...@googlegroups.com
#26889: Index creation different if SlugField in CreateModel or in AddField of a
migration on postgresql
-------------------------------------+-------------------------------------
Reporter: aRkadeFR | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:
Keywords: migrations, index, | Triage Stage: Accepted
postgresql, slugfield db-indexes |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* keywords: migrations, index, postgresql, slugfield => migrations, index,
postgresql, slugfield db-indexes
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

This looks like the same issue as #25412 but for `AddField` instead of
`AlterField`.

--
Ticket URL: <https://code.djangoproject.com/ticket/26889#comment:1>

Django

unread,
Jul 12, 2016, 9:37:02 PM7/12/16
to django-...@googlegroups.com
#26889: Index creation different if SlugField in CreateModel or in AddField of a
migration on postgresql
-------------------------------------+-------------------------------------
Reporter: aRkadeFR | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 1.9
Severity: Normal | Resolution:
Keywords: migrations, index, | Triage Stage: Accepted
postgresql, slugfield db-indexes |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jdufresne):

* cc: jon.dufresne@… (added)
* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/6909

--
Ticket URL: <https://code.djangoproject.com/ticket/26889#comment:2>

Django

unread,
Jul 13, 2016, 4:01:47 PM7/13/16
to django-...@googlegroups.com
#26889: Index creation different if SlugField in CreateModel or in AddField of a
migration on postgresql
-------------------------------------+-------------------------------------
Reporter: aRkadeFR | Owner: nobody
Type: Bug | Status: new

Component: Migrations | Version: 1.9
Severity: Normal | Resolution:
Keywords: migrations, index, | Triage Stage: Ready for
postgresql, slugfield db-indexes | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26889#comment:3>

Django

unread,
Jul 13, 2016, 9:55:25 PM7/13/16
to django-...@googlegroups.com
#26889: Index creation different if SlugField in CreateModel or in AddField of a
migration on postgresql
-------------------------------------+-------------------------------------
Reporter: aRkadeFR | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: fixed

Keywords: migrations, index, | Triage Stage: Ready for
postgresql, slugfield db-indexes | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jon Dufresne <jon.dufresne@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"2e4cfcd2b9a0984ad6c4087a5deebbf33413835c" 2e4cfcd2]:
{{{
#!CommitTicketReference repository=""
revision="2e4cfcd2b9a0984ad6c4087a5deebbf33413835c"
Fixed #26889 -- Fixed missing PostgreSQL index in
SchemaEditor.add_field().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26889#comment:4>

Django

unread,
Jul 13, 2016, 10:06:34 PM7/13/16
to django-...@googlegroups.com
#26889: Index creation different if SlugField in CreateModel or in AddField of a
migration on postgresql
-------------------------------------+-------------------------------------
Reporter: aRkadeFR | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: fixed
Keywords: migrations, index, | Triage Stage: Ready for
postgresql, slugfield db-indexes | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"b6af8b6f2e15f4302205975d8519a8c0f5650e57" b6af8b6]:
{{{
#!CommitTicketReference repository=""
revision="b6af8b6f2e15f4302205975d8519a8c0f5650e57"
[1.9.x] Fixed #26889 -- Fixed missing PostgreSQL index in
SchemaEditor.add_field().

Backport of 2e4cfcd2b9a0984ad6c4087a5deebbf33413835c from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26889#comment:5>

Django

unread,
Jul 13, 2016, 10:06:36 PM7/13/16
to django-...@googlegroups.com
#26889: Index creation different if SlugField in CreateModel or in AddField of a
migration on postgresql
-------------------------------------+-------------------------------------
Reporter: aRkadeFR | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: fixed
Keywords: migrations, index, | Triage Stage: Ready for
postgresql, slugfield db-indexes | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"1a2ee697e0631475d95197a795aa2af762537b10" 1a2ee697]:
{{{
#!CommitTicketReference repository=""
revision="1a2ee697e0631475d95197a795aa2af762537b10"
[1.10.x] Fixed #26889 -- Fixed missing PostgreSQL index in
SchemaEditor.add_field().

Backport of 2e4cfcd2b9a0984ad6c4087a5deebbf33413835c from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26889#comment:6>

Django

unread,
Jul 13, 2016, 10:16:04 PM7/13/16
to django-...@googlegroups.com
#26889: Index creation different if SlugField in CreateModel or in AddField of a
migration on postgresql
-------------------------------------+-------------------------------------
Reporter: aRkadeFR | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: fixed
Keywords: migrations, index, | Triage Stage: Ready for
postgresql, slugfield db-indexes | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"8edfdddbc8d6a4e39c4bf175075822ca3751b054" 8edfdddb]:
{{{
#!CommitTicketReference repository=""
revision="8edfdddbc8d6a4e39c4bf175075822ca3751b054"
[1.8.x] Fixed #26889 -- Fixed missing PostgreSQL index in
SchemaEditor.add_field().

Backport of 2e4cfcd2b9a0984ad6c4087a5deebbf33413835c from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26889#comment:7>

Django

unread,
Jul 15, 2016, 10:34:46 AM7/15/16
to django-...@googlegroups.com
#26889: Index creation different if SlugField in CreateModel or in AddField of a
migration on postgresql
-------------------------------------+-------------------------------------
Reporter: aRkadeFR | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: fixed
Keywords: migrations, index, | Triage Stage: Ready for
postgresql, slugfield db-indexes | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"3f76d1402dac9c2993d588f996dc1c331edbc9a7" 3f76d140]:
{{{
#!CommitTicketReference repository=""
revision="3f76d1402dac9c2993d588f996dc1c331edbc9a7"
Refs #26889 -- Refactored SchemaEditor to allow backend specific indexes.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26889#comment:8>

Django

unread,
Jul 20, 2016, 6:06:20 AM7/20/16
to django-...@googlegroups.com
#26889: Index creation different if SlugField in CreateModel or in AddField of a
migration on postgresql
-------------------------------------+-------------------------------------
Reporter: aRkadeFR | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: fixed
Keywords: migrations, index, | Triage Stage: Ready for
postgresql, slugfield db-indexes | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aRkadeFR):

Thanks for the work done :)

--
Ticket URL: <https://code.djangoproject.com/ticket/26889#comment:9>

Reply all
Reply to author
Forward
0 new messages