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.
--
Ticket URL: <https://code.djangoproject.com/ticket/25412>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => assigned
* needs_better_patch: => 0
* owner: nobody => bsebi
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/25412#comment:1>
* version: 1.8 => master
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
Thanks to the provided sample project I managed to reproduce.
Looks like someone [https://code.djangoproject.com/ticket/24088#comment:5
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/25412#comment:2>
* owner: bsebi => synasius
--
Ticket URL: <https://code.djangoproject.com/ticket/25412#comment:3>
* has_patch: 0 => 1
Comment:
Pull request here: https://github.com/django/django/pull/5603
--
Ticket URL: <https://code.djangoproject.com/ticket/25412#comment:4>
* needs_better_patch: 0 => 1
Comment:
Left some comments on the patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/25412#comment:5>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/25412#comment:6>
* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/25412#comment:7>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
Comment:
All comments have been addressed.
--
Ticket URL: <https://code.djangoproject.com/ticket/25412#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"3a36c8079544c83dcdea4e52181efcd2d1e86b9c" 3a36c807]:
{{{
#!CommitTicketReference repository=""
revision="3a36c8079544c83dcdea4e52181efcd2d1e86b9c"
Fixed #25412 -- Fixed missing PostgreSQL index on Char/TextField when
using AlterField.
Thanks to Emanuele Palazzetti for the help.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25412#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"722fae4b5159b2810e252e3385936f86f04eb09b" 722fae4b]:
{{{
#!CommitTicketReference repository=""
revision="722fae4b5159b2810e252e3385936f86f04eb09b"
[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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25412#comment:10>
Comment (by Tim Graham <timograham@…>):
In [changeset:"905e94a07e557f470fd1d01e7cd067cdae2b7794" 905e94a0]:
{{{
#!CommitTicketReference repository=""
revision="905e94a07e557f470fd1d01e7cd067cdae2b7794"
[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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25412#comment:11>