#35180: PostgreSQL pattern ops indexes are dropped when changing between 
CharField
and TextField
-------------------------------------+-------------------------------------
               Reporter:  Robin Ray  |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  5.0
  layer (models, ORM)                |       Keywords:  index postgres
               Severity:  Normal     |  migration
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 When converting an indexed CharField to a TextField (and vice versa) on
 PostgreSQL, Django drops the existing pattern ops `_like` index for the
 column but does not recreate it with the new pattern ops. When reversing
 the migration, Django does not recreate the initial `_like` index.

 I have been able to reproduce this behavior in Django 3.2 and 5.0.

 **Reproduction**

 1. Given a model with a CharField that has `db_index=True` on a PostgreSQL
 database
 2. Inspect the database indexes or migration SQL and see that the indexed
 CharField has two indexes, one of which ends in `_like` and uses
 `varchar_pattern_ops`
 3. Change the CharField to a TextField and generate a migration
 4. Run the migration or inspect the SQL with the `sqlmigrate` manage
 command
 5. Inspect the database indexes or migration SQL and see that the indexed
 TextField does not have a `_like` index
 6. Reverse the migration
 7. Inspect the database indexes or migration SQL and see that the indexed
 CharField no longer has a `_like` index

 Here is an example project that demonstratest the issue:
 https://github.com/robin-ray/alter_text_index_repro
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35180>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018d93c9db6f-16c3b072-21b6-48ff-8bcd-0ca0e857fd2a-000000%40eu-central-1.amazonses.com.

Reply via email to