mirror of
https://github.com/django/django.git
synced 2025-09-08 03:30:48 +00:00
Fixed #26889 -- Fixed missing PostgreSQL index in SchemaEditor.add_field().
This commit is contained in:
parent
10883b63b7
commit
2e4cfcd2b9
5 changed files with 50 additions and 1 deletions
|
@ -1907,6 +1907,32 @@ class SchemaTests(TransactionTestCase):
|
|||
with connection.schema_editor() as editor:
|
||||
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue