Opened 9 months ago
Last modified 5 days ago
#35180 closed Bug
PostgreSQL pattern ops indexes are dropped when changing between CharField and TextField — at Initial Version
Reported by: | Robin Ray | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | index postgres migration |
Cc: | Simon Charette, Mariusz Felisiak, bcail | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
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
- Given a model with a CharField that has
db_index=True
on a PostgreSQL database - Inspect the database indexes or migration SQL and see that the indexed CharField has two indexes, one of which ends in
_like
and usesvarchar_pattern_ops
- Change the CharField to a TextField and generate a migration
- Run the migration or inspect the SQL with the
sqlmigrate
manage command - Inspect the database indexes or migration SQL and see that the indexed TextField does not have a
_like
index - Reverse the migration
- 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
Note:
See TracTickets
for help on using tickets.