#28646: Migration calls "CREATE INDEX" when one already exists when 'unique'
field
attribute is added
-------------------------------------+-------------------------------------
Reporter: Hari - 何瑞理 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
postgresql,migration,index | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ariki):
* status: closed => new
* resolution: worksforme =>
Comment:
Django tries to create a like index twice and fails when I try to make
existing SlugField a primary key in a manually written migration. The code
to reproduce:
{{{
import unittest
from django.db import connection, migrations, models
from django.db.migrations.state import ProjectState
from django.test import TestCase
class ChangePrimaryKeyTest(TestCase):
def test_change_primary_key(self):
# Set PostgreSQL messages locale to get error messages
operation0 = migrations.RunSQL("SET lc_messages = 'C';")
# 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()
with connection.schema_editor() as editor:
new_state = project_state.clone()
operation0.database_forwards(
"migrtest", editor, project_state, new_state)
operation1.state_forwards("migrtest", new_state)
operation1.database_forwards(
"migrtest", editor, project_state, new_state)
project_state, new_state = new_state, new_state.clone()
operation2.state_forwards("migrtest", new_state)
operation2.database_forwards(
"migrtest", editor, project_state, new_state)
project_state, new_state = new_state, new_state.clone()
operation3.state_forwards("migrtest", new_state)
operation3.database_forwards(
"migrtest", editor, project_state, new_state)
}}}
Error message:
{{{
ERROR: test_change_primary_key (migrtest.tests.ChangePrimaryKeyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py",
line 65, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation
"migrtest_simplemodel_field2_972171aa_like" already exists
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28646#comment:4>
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.ae4fc4f9f3024e2cc4bf006691ff8df7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.