#26805: Dropping unique from CharField does not drop PostgreSQL _like index
----------------------------+--------------------
Reporter: jdufresne | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
If a `CharField` is created with `unique=True` and without `db_index=True`
the PostgreSQL `_like` index is added to the field. (Good)
Later, if `unique` is removed from the field. The unique constraint is
removed during migrations, but the corresponding `_like` index is not
cleaned up.
The following unit test demonstrates this behavior. It was adapted from
[https://github.com/django/django/blob/ca77b509059831b055a3b735ff77e042f8e1c0eb/tests/schema/tests.py#L1813-L1841
similar tests] in `schema/tests.py`:
{{{#!python
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL
specific")
def test_alter_field_drop_unique_from_charfield(self):
# Create the table and verify initial indexes.
with connection.schema_editor() as editor:
editor.create_model(Tag)
self.assertEqual(
self.get_constraints_for_column(Tag, 'slug'),
['schema_tag_slug_2c418ba3_like', 'schema_tag_slug_key']
)
# Alter to drop unique
old_field = Tag._meta.get_field('slug')
new_field = SlugField()
new_field.set_attributes_from_name('slug')
with connection.schema_editor() as editor:
editor.alter_field(Tag, old_field, new_field, strict=True)
self.assertEqual(self.get_constraints_for_column(Tag, 'slug'), [])
}}}
Running this produces the following failure:
{{{
======================================================================
FAIL: test_alter_field_drop_unique_from_charfield
(schema.tests.SchemaTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/jon/devel/django/tests/schema/tests.py", line 1858, in
test_alter_field_drop_unique_from_charfield
self.assertEqual(self.get_constraints_for_column(Tag, 'slug'), [])
AssertionError: Lists differ: ['schema_tag_slug_2c418ba3_like'] != []
First list contains 1 additional elements.
First extra element 0:
schema_tag_slug_2c418ba3_like
- ['schema_tag_slug_2c418ba3_like']
+ []
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26805>
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/052.8f1c64d3f9da01a5ce320d4358150bf9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.