Tests the RemoveField operation.
(self)
| 2040 | self.apply_operations("test_rmflmmwt", project_state, operations=operations) |
| 2041 | |
| 2042 | def test_remove_field(self): |
| 2043 | """ |
| 2044 | Tests the RemoveField operation. |
| 2045 | """ |
| 2046 | project_state = self.set_up_test_model("test_rmfl") |
| 2047 | # Test the state alteration |
| 2048 | operation = migrations.RemoveField("Pony", "pink") |
| 2049 | self.assertEqual(operation.describe(), "Remove field pink from Pony") |
| 2050 | self.assertEqual( |
| 2051 | operation.formatted_description(), "- Remove field pink from Pony" |
| 2052 | ) |
| 2053 | self.assertEqual(operation.migration_name_fragment, "remove_pony_pink") |
| 2054 | new_state = project_state.clone() |
| 2055 | operation.state_forwards("test_rmfl", new_state) |
| 2056 | self.assertEqual(len(new_state.models["test_rmfl", "pony"].fields), 4) |
| 2057 | # Test the database alteration |
| 2058 | self.assertColumnExists("test_rmfl_pony", "pink") |
| 2059 | with ( |
| 2060 | connection.schema_editor() as editor, |
| 2061 | CaptureQueriesContext(connection) as ctx, |
| 2062 | ): |
| 2063 | operation.database_forwards("test_rmfl", editor, project_state, new_state) |
| 2064 | self.assertGreater(len(ctx.captured_queries), 0) |
| 2065 | self.assertNotIn("CASCADE", ctx.captured_queries[-1]["sql"]) |
| 2066 | self.assertColumnNotExists("test_rmfl_pony", "pink") |
| 2067 | # And test reversal |
| 2068 | with connection.schema_editor() as editor: |
| 2069 | operation.database_backwards("test_rmfl", editor, new_state, project_state) |
| 2070 | self.assertColumnExists("test_rmfl_pony", "pink") |
| 2071 | # And deconstruction |
| 2072 | definition = operation.deconstruct() |
| 2073 | self.assertEqual(definition[0], "RemoveField") |
| 2074 | self.assertEqual(definition[1], []) |
| 2075 | self.assertEqual(definition[2], {"model_name": "Pony", "name": "pink"}) |
| 2076 | |
| 2077 | def test_remove_fk(self): |
| 2078 | """ |
nothing calls this directly
no test coverage detected