Tests simple altering of fields
(self)
| 1115 | self.assertNotIn("char_field", columns) |
| 1116 | |
| 1117 | def test_alter(self): |
| 1118 | """ |
| 1119 | Tests simple altering of fields |
| 1120 | """ |
| 1121 | # Create the table |
| 1122 | with connection.schema_editor() as editor: |
| 1123 | editor.create_model(Author) |
| 1124 | # Ensure the field is right to begin with |
| 1125 | columns = self.column_classes(Author) |
| 1126 | self.assertEqual( |
| 1127 | columns["name"][0], |
| 1128 | connection.features.introspected_field_types["CharField"], |
| 1129 | ) |
| 1130 | self.assertEqual( |
| 1131 | bool(columns["name"][1][6]), |
| 1132 | bool(connection.features.interprets_empty_strings_as_nulls), |
| 1133 | ) |
| 1134 | # Alter the name field to a TextField |
| 1135 | old_field = Author._meta.get_field("name") |
| 1136 | new_field = TextField(null=True) |
| 1137 | new_field.set_attributes_from_name("name") |
| 1138 | with connection.schema_editor() as editor: |
| 1139 | editor.alter_field(Author, old_field, new_field, strict=True) |
| 1140 | columns = self.column_classes(Author) |
| 1141 | self.assertEqual(columns["name"][0], "TextField") |
| 1142 | self.assertTrue(columns["name"][1][6]) |
| 1143 | # Change nullability again |
| 1144 | new_field2 = TextField(null=False) |
| 1145 | new_field2.set_attributes_from_name("name") |
| 1146 | with connection.schema_editor() as editor: |
| 1147 | editor.alter_field(Author, new_field, new_field2, strict=True) |
| 1148 | columns = self.column_classes(Author) |
| 1149 | self.assertEqual(columns["name"][0], "TextField") |
| 1150 | self.assertEqual( |
| 1151 | bool(columns["name"][1][6]), |
| 1152 | bool(connection.features.interprets_empty_strings_as_nulls), |
| 1153 | ) |
| 1154 | |
| 1155 | def test_alter_auto_field_to_integer_field(self): |
| 1156 | # Create the table |
nothing calls this directly
no test coverage detected