#35180: PostgreSQL pattern ops indexes are dropped when changing between 
CharField
and TextField
-------------------------------------+-------------------------------------
     Reporter:  Robin Ray            |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  5.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  index postgres       |             Triage Stage:
  migration                          |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Robin Ray:

Old description:

> 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

New description:

 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 demonstrates the issue: https://github.com
 /robin-ray/alter_text_index_repro

--
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35180#comment:1>
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/0107018d93cf9bea-a8898e30-3ef1-4131-b098-9486b5f9e9c9-000000%40eu-central-1.amazonses.com.

Reply via email to