#26889 closed Bug (fixed)
Index creation different if SlugField in CreateModel or in AddField of a migration on postgresql
| Reported by: | aRkadeFR | Owned by: | nobody |
|---|---|---|---|
| Component: | Migrations | Version: | 1.9 |
| Severity: | Normal | Keywords: | migrations, index, postgresql, slugfield db-indexes |
| Cc: | jon.dufresne@… | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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
Change History (9)
comment:1 by , 9 years ago
| Keywords: | db-indexes added |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 9 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
This looks like the same issue as #25412 but for
AddFieldinstead ofAlterField.