MCPcopy
hub / github.com/django/django / test_alter_db_comment_foreign_key

Method test_alter_db_comment_foreign_key

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

Source from the content-addressed store, hash-verified

5085
5086 @skipUnlessDBFeature("supports_comments", "supports_foreign_keys")
5087 def test_alter_db_comment_foreign_key(self):
5088 with connection.schema_editor() as editor:
5089 editor.create_model(Author)
5090 editor.create_model(Book)
5091
5092 comment = "FK custom comment"
5093 old_field = Book._meta.get_field("author")
5094 new_field = ForeignKey(Author, CASCADE, db_comment=comment)
5095 new_field.set_attributes_from_name("author")
5096 with connection.schema_editor() as editor:
5097 editor.alter_field(Book, old_field, new_field, strict=True)
5098 self.assertEqual(
5099 self.get_column_comment(Book._meta.db_table, "author_id"),
5100 comment,
5101 )
5102
5103 @skipUnlessDBFeature("supports_comments")
5104 def test_alter_field_type_preserve_comment(self):

Callers

nothing calls this directly

Calls 7

get_column_commentMethod · 0.95
ForeignKeyClass · 0.90
schema_editorMethod · 0.80
create_modelMethod · 0.45
get_fieldMethod · 0.45
alter_fieldMethod · 0.45

Tested by

no test coverage detected