Tests the AlterField operation.
(self)
| 2237 | self.assertColumnExists(m2m_table, "stable_id") |
| 2238 | |
| 2239 | def test_alter_field(self): |
| 2240 | """ |
| 2241 | Tests the AlterField operation. |
| 2242 | """ |
| 2243 | project_state = self.set_up_test_model("test_alfl") |
| 2244 | # Test the state alteration |
| 2245 | operation = migrations.AlterField( |
| 2246 | "Pony", "pink", models.IntegerField(null=True) |
| 2247 | ) |
| 2248 | self.assertEqual(operation.describe(), "Alter field pink on Pony") |
| 2249 | self.assertEqual( |
| 2250 | operation.formatted_description(), "~ Alter field pink on Pony" |
| 2251 | ) |
| 2252 | self.assertEqual(operation.migration_name_fragment, "alter_pony_pink") |
| 2253 | new_state = project_state.clone() |
| 2254 | operation.state_forwards("test_alfl", new_state) |
| 2255 | self.assertIs( |
| 2256 | project_state.models["test_alfl", "pony"].fields["pink"].null, False |
| 2257 | ) |
| 2258 | self.assertIs(new_state.models["test_alfl", "pony"].fields["pink"].null, True) |
| 2259 | # Test the database alteration |
| 2260 | self.assertColumnNotNull("test_alfl_pony", "pink") |
| 2261 | with connection.schema_editor() as editor: |
| 2262 | operation.database_forwards("test_alfl", editor, project_state, new_state) |
| 2263 | self.assertColumnNull("test_alfl_pony", "pink") |
| 2264 | # And test reversal |
| 2265 | with connection.schema_editor() as editor: |
| 2266 | operation.database_backwards("test_alfl", editor, new_state, project_state) |
| 2267 | self.assertColumnNotNull("test_alfl_pony", "pink") |
| 2268 | # And deconstruction |
| 2269 | definition = operation.deconstruct() |
| 2270 | self.assertEqual(definition[0], "AlterField") |
| 2271 | self.assertEqual(definition[1], []) |
| 2272 | self.assertEqual(sorted(definition[2]), ["field", "model_name", "name"]) |
| 2273 | |
| 2274 | def test_alter_field_add_database_default(self): |
| 2275 | app_label = "test_alfladd" |
nothing calls this directly
no test coverage detected