﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26889	Index creation different if SlugField in CreateModel or in AddField of a migration on postgresql	aRkadeFR	nobody	"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"	Bug	closed	Migrations	1.9	Normal	fixed	migrations, index, postgresql, slugfield db-indexes	jon.dufresne@…	Ready for checkin	1	0	0	0	0	0
