MCPcopy
hub / github.com/django/django / test_alter_field_add_unique_to_charfield

Method test_alter_field_add_unique_to_charfield

tests/schema/tests.py:5236–5254  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5234
5235 @unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific")
5236 def test_alter_field_add_unique_to_charfield(self):
5237 # Create the table and verify no initial indexes.
5238 with connection.schema_editor() as editor:
5239 editor.create_model(Author)
5240 self.assertEqual(self.get_constraints_for_column(Author, "name"), [])
5241 # Alter to add unique=True and create 2 indexes.
5242 old_field = Author._meta.get_field("name")
5243 new_field = CharField(max_length=255, unique=True)
5244 new_field.set_attributes_from_name("name")
5245 with connection.schema_editor() as editor:
5246 editor.alter_field(Author, old_field, new_field, strict=True)
5247 self.assertEqual(
5248 self.get_constraints_for_column(Author, "name"),
5249 ["schema_author_name_1fbc5617_like", "schema_author_name_1fbc5617_uniq"],
5250 )
5251 # Remove unique=True to drop both indexes.
5252 with connection.schema_editor() as editor:
5253 editor.alter_field(Author, new_field, old_field, strict=True)
5254 self.assertEqual(self.get_constraints_for_column(Author, "name"), [])
5255
5256 @unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific")
5257 def test_alter_field_add_index_to_textfield(self):

Callers

nothing calls this directly

Calls 7

CharFieldClass · 0.90
schema_editorMethod · 0.80
create_modelMethod · 0.45
get_fieldMethod · 0.45
alter_fieldMethod · 0.45

Tested by

no test coverage detected