Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#25412 closed Bug (fixed)

Migrate command does not create index with operator class for CharField

Reported by: Federico Frenguelli Owned by: Federico Frenguelli
Component: Migrations Version: master
Severity: Normal Keywords:
Cc: 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

./manage.py migrate command does not create an additional index with the operator class for a CharField, when db_index=True is added to an existing field.

I created a sample project to reproduce the error here: https://github.com/synasius/foo

There are two models, Person and Car.
Person's "name" field was migrated with db_index=True and if I run ./manage.py sqlmigrate bar 0001 I can see both the indexes, one using the operator class varchar_pattern_ops.

The issue occurs when db_index=True is added to Car's name field and then a migration is created. When I run ./manage.py sqlmigrate bar 0002 I can only see one plain index.

I reproduced the issue in Django 1.7.x, 1.8.x and master. I'm using postgresql 9.4.4.

Change History (11)

comment:1 Changed 4 years ago by Sebastian Brestin

Owner: changed from nobody to Sebastian Brestin
Status: newassigned

comment:2 Changed 4 years ago by Simon Charette

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug
Version: 1.8master

Thanks to the provided sample project I managed to reproduce.

Looks like someone commented on a related ticket to report this inconsistency.

Another oddity is the fact the default non-unique index created has a name ending with _uniq which looks quite suspicious.

comment:3 Changed 4 years ago by Federico Frenguelli

Owner: changed from Sebastian Brestin to Federico Frenguelli

comment:4 Changed 4 years ago by Federico Frenguelli

Has patch: set

comment:5 Changed 4 years ago by Simon Charette

Patch needs improvement: set

Left some comments on the patch.

comment:6 Changed 4 years ago by Simon Charette

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:7 Changed 4 years ago by Tim Graham

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:8 Changed 4 years ago by Simon Charette

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

All comments have been addressed.

comment:9 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 3a36c807:

Fixed #25412 -- Fixed missing PostgreSQL index on Char/TextField when using AlterField.

Thanks to Emanuele Palazzetti for the help.

comment:10 Changed 4 years ago by Tim Graham <timograham@…>

In 722fae4b:

[1.9.x] Fixed #25412 -- Fixed missing PostgreSQL index on Char/TextField when using AlterField.

Thanks to Emanuele Palazzetti for the help.

Backport of 3a36c8079544c83dcdea4e52181efcd2d1e86b9c from master

comment:11 Changed 4 years ago by Tim Graham <timograham@…>

In 905e94a0:

[1.8.x] Fixed #25412 -- Fixed missing PostgreSQL index on Char/TextField when using AlterField.

Thanks to Emanuele Palazzetti for the help.

Backport of 3a36c8079544c83dcdea4e52181efcd2d1e86b9c from master

Note: See TracTickets for help on using tickets.
Back to Top