summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2016-07-12 17:50:17 -0700
committerTim Graham <timograham@gmail.com>2016-07-13 22:03:09 -0400
commitb6af8b6f2e15f4302205975d8519a8c0f5650e57 (patch)
tree516c098cca7d38c8b4324cd51e04c496c63f1b82 /tests
parente6db7271547087034b1ee2db11676601706e67a3 (diff)
[1.9.x] Fixed #26889 -- Fixed missing PostgreSQL index in SchemaEditor.add_field().
Backport of 2e4cfcd2b9a0984ad6c4087a5deebbf33413835c from master
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 957d9cb9b1..2032743db1 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -1718,6 +1718,32 @@ class SchemaTests(TransactionTestCase):
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")
def test_alter_field_add_index_to_charfield(self):
# Create the table and verify no initial indexes.
with connection.schema_editor() as editor: