#28646: Migration calls "CREATE INDEX" when one already exists when 'unique'
field
attribute is added (PostgreSQL)
-------------------------------------+-------------------------------------
Reporter: Hari - 何瑞理 | Owner: Tomer
| Chachamu
Type: Bug | Status: assigned
Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
postgresql,migration,index |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tomer Chachamu):
The test case given is incorrect, as Django always uses a fresh schema
editor for each migration step:
https://github.com/django/django/blob/master/django/db/migrations/executor.py#L225
This passes and is similar to other cases in
{{{migrations/test_operations.py}}}:
{{{
def test_change_primary_key(self):
# Create a model with two fields
operation1 = migrations.CreateModel(
'SimpleModel',
[
("field1", models.SlugField(max_length=20,
primary_key=True)),
("field2", models.SlugField(max_length=20)),
],
)
# Drop field1 primary key constraint - this doesn't fail
operation2 = migrations.AlterField(
"SimpleModel",
"field1",
models.SlugField(max_length=20, primary_key=False),
)
# Add a primary key constraint to field2 - this fails
operation3 = migrations.AlterField(
"SimpleModel",
"field2",
models.SlugField(max_length=20, primary_key=True),
)
project_state = ProjectState()
new_state = project_state.clone()
operation1.state_forwards("migrtest", new_state)
with connection.schema_editor() as editor:
operation1.database_forwards("migrtest", editor,
project_state, new_state)
project_state, new_state = new_state, new_state.clone()
operation2.state_forwards("migrtest", new_state)
with connection.schema_editor() as editor:
operation2.database_forwards("migrtest", editor,
project_state, new_state)
project_state, new_state = new_state, new_state.clone()
operation3.state_forwards("migrtest", new_state)
with connection.schema_editor() as editor:
operation3.database_forwards("migrtest", editor,
project_state, new_state)
}}}
I'm going to try working off the original bug description to reproduce the
bug.
--
Ticket URL: <https://code.djangoproject.com/ticket/28646#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.e98a67a770864ae00821caeab06039f0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.