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.
* 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>
* 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>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/26889#comment:3>
* 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>
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>
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>
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>
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>
Comment (by aRkadeFR):
Thanks for the work done :)
--
Ticket URL: <https://code.djangoproject.com/ticket/26889#comment:9>