[1.10.x] Fixed #26889 -- Fixed missing PostgreSQL index in SchemaEditor.add_field().
Backport of 2e4cfcd2b9
from master
This commit is contained in:
parent
ded5020241
commit
1a2ee697e0
|
@ -17,6 +17,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||||
def quote_value(self, value):
|
def quote_value(self, value):
|
||||||
return psycopg2.extensions.adapt(value)
|
return psycopg2.extensions.adapt(value)
|
||||||
|
|
||||||
|
def add_field(self, model, field):
|
||||||
|
super(DatabaseSchemaEditor, self).add_field(model, field)
|
||||||
|
like_index_statement = self._create_like_index_sql(model, field)
|
||||||
|
if like_index_statement is not None:
|
||||||
|
self.deferred_sql.append(like_index_statement)
|
||||||
|
|
||||||
def _model_indexes_sql(self, model):
|
def _model_indexes_sql(self, model):
|
||||||
output = super(DatabaseSchemaEditor, self)._model_indexes_sql(model)
|
output = super(DatabaseSchemaEditor, self)._model_indexes_sql(model)
|
||||||
if not model._meta.managed or model._meta.proxy or model._meta.swapped:
|
if not model._meta.managed or model._meta.proxy or model._meta.swapped:
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
===========================
|
||||||
|
Django 1.8.14 release notes
|
||||||
|
===========================
|
||||||
|
|
||||||
|
*Under development*
|
||||||
|
|
||||||
|
Django 1.8.14 fixes several bugs in 1.8.13.
|
||||||
|
|
||||||
|
Bugfixes
|
||||||
|
========
|
||||||
|
|
||||||
|
* Fixed missing ``varchar/text_pattern_ops`` index on ``CharField`` and
|
||||||
|
``TextField`` respectively when using ``AddField`` on PostgreSQL
|
||||||
|
(:ticket:`26889`).
|
|
@ -9,4 +9,6 @@ Django 1.9.8 fixes several bugs in 1.9.7.
|
||||||
Bugfixes
|
Bugfixes
|
||||||
========
|
========
|
||||||
|
|
||||||
* ...
|
* Fixed missing ``varchar/text_pattern_ops`` index on ``CharField`` and
|
||||||
|
``TextField`` respectively when using ``AddField`` on PostgreSQL
|
||||||
|
(:ticket:`26889`).
|
||||||
|
|
|
@ -47,6 +47,7 @@ versions of the documentation contain the release notes for any later releases.
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 1
|
:maxdepth: 1
|
||||||
|
|
||||||
|
1.8.14
|
||||||
1.8.13
|
1.8.13
|
||||||
1.8.12
|
1.8.12
|
||||||
1.8.11
|
1.8.11
|
||||||
|
|
|
@ -1738,6 +1738,32 @@ class SchemaTests(TransactionTestCase):
|
||||||
with connection.schema_editor() as editor:
|
with connection.schema_editor() as editor:
|
||||||
editor.add_field(Author, new_field)
|
editor.add_field(Author, new_field)
|
||||||
|
|
||||||
|
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific")
|
||||||
|
def test_add_indexed_charfield(self):
|
||||||
|
field = CharField(max_length=255, db_index=True)
|
||||||
|
field.set_attributes_from_name('nom_de_plume')
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
editor.create_model(Author)
|
||||||
|
editor.add_field(Author, field)
|
||||||
|
# Should create two indexes; one for like operator.
|
||||||
|
self.assertEqual(
|
||||||
|
self.get_constraints_for_column(Author, 'nom_de_plume'),
|
||||||
|
['schema_author_95aa9e9b', 'schema_author_nom_de_plume_7570a851_like'],
|
||||||
|
)
|
||||||
|
|
||||||
|
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific")
|
||||||
|
def test_add_unique_charfield(self):
|
||||||
|
field = CharField(max_length=255, unique=True)
|
||||||
|
field.set_attributes_from_name('nom_de_plume')
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
editor.create_model(Author)
|
||||||
|
editor.add_field(Author, field)
|
||||||
|
# Should create two indexes; one for like operator.
|
||||||
|
self.assertEqual(
|
||||||
|
self.get_constraints_for_column(Author, 'nom_de_plume'),
|
||||||
|
['schema_author_nom_de_plume_7570a851_like', 'schema_author_nom_de_plume_key']
|
||||||
|
)
|
||||||
|
|
||||||
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific")
|
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific")
|
||||||
def test_alter_field_add_index_to_charfield(self):
|
def test_alter_field_add_index_to_charfield(self):
|
||||||
# Create the table and verify no initial indexes.
|
# Create the table and verify no initial indexes.
|
||||||
|
|
Loading…
Reference in New Issue