(self)
| 5050 | |
| 5051 | @skipUnlessDBFeature("supports_comments") |
| 5052 | def test_alter_db_comment(self): |
| 5053 | with connection.schema_editor() as editor: |
| 5054 | editor.create_model(Author) |
| 5055 | # Add comment. |
| 5056 | old_field = Author._meta.get_field("name") |
| 5057 | new_field = CharField(max_length=255, db_comment="Custom comment") |
| 5058 | new_field.set_attributes_from_name("name") |
| 5059 | with connection.schema_editor() as editor: |
| 5060 | editor.alter_field(Author, old_field, new_field, strict=True) |
| 5061 | self.assertEqual( |
| 5062 | self.get_column_comment(Author._meta.db_table, "name"), |
| 5063 | "Custom comment", |
| 5064 | ) |
| 5065 | # Alter comment. |
| 5066 | old_field = new_field |
| 5067 | new_field = CharField(max_length=255, db_comment="New custom comment") |
| 5068 | new_field.set_attributes_from_name("name") |
| 5069 | with connection.schema_editor() as editor: |
| 5070 | editor.alter_field(Author, old_field, new_field, strict=True) |
| 5071 | self.assertEqual( |
| 5072 | self.get_column_comment(Author._meta.db_table, "name"), |
| 5073 | "New custom comment", |
| 5074 | ) |
| 5075 | # Remove comment. |
| 5076 | old_field = new_field |
| 5077 | new_field = CharField(max_length=255) |
| 5078 | new_field.set_attributes_from_name("name") |
| 5079 | with connection.schema_editor() as editor: |
| 5080 | editor.alter_field(Author, old_field, new_field, strict=True) |
| 5081 | self.assertIn( |
| 5082 | self.get_column_comment(Author._meta.db_table, "name"), |
| 5083 | [None, ""], |
| 5084 | ) |
| 5085 | |
| 5086 | @skipUnlessDBFeature("supports_comments", "supports_foreign_keys") |
| 5087 | def test_alter_db_comment_foreign_key(self): |
nothing calls this directly
no test coverage detected