Tests the AddField operation.
(self)
| 1430 | self.assertTableExists(app_label + "_other") |
| 1431 | |
| 1432 | def test_add_field(self): |
| 1433 | """ |
| 1434 | Tests the AddField operation. |
| 1435 | """ |
| 1436 | # Test the state alteration |
| 1437 | operation = migrations.AddField( |
| 1438 | "Pony", |
| 1439 | "height", |
| 1440 | models.FloatField(null=True, default=5), |
| 1441 | ) |
| 1442 | self.assertEqual(operation.describe(), "Add field height to Pony") |
| 1443 | self.assertEqual( |
| 1444 | operation.formatted_description(), "+ Add field height to Pony" |
| 1445 | ) |
| 1446 | self.assertEqual(operation.migration_name_fragment, "pony_height") |
| 1447 | project_state, new_state = self.make_test_state("test_adfl", operation) |
| 1448 | self.assertEqual(len(new_state.models["test_adfl", "pony"].fields), 6) |
| 1449 | field = new_state.models["test_adfl", "pony"].fields["height"] |
| 1450 | self.assertEqual(field.default, 5) |
| 1451 | # Test the database alteration |
| 1452 | self.assertColumnNotExists("test_adfl_pony", "height") |
| 1453 | with connection.schema_editor() as editor: |
| 1454 | operation.database_forwards("test_adfl", editor, project_state, new_state) |
| 1455 | self.assertColumnExists("test_adfl_pony", "height") |
| 1456 | # And test reversal |
| 1457 | with connection.schema_editor() as editor: |
| 1458 | operation.database_backwards("test_adfl", editor, new_state, project_state) |
| 1459 | self.assertColumnNotExists("test_adfl_pony", "height") |
| 1460 | # And deconstruction |
| 1461 | definition = operation.deconstruct() |
| 1462 | self.assertEqual(definition[0], "AddField") |
| 1463 | self.assertEqual(definition[1], []) |
| 1464 | self.assertEqual(sorted(definition[2]), ["field", "model_name", "name"]) |
| 1465 | |
| 1466 | @skipUnlessDBFeature("supports_stored_generated_columns") |
| 1467 | def test_add_generated_field(self): |
nothing calls this directly
no test coverage detected