Remove a field from a model. Usually involves deleting a column, but for M2Ms may involve deleting a table.
(self, model, field)
| 331 | super().add_field(model, field) |
| 332 | |
| 333 | def remove_field(self, model, field): |
| 334 | """ |
| 335 | Remove a field from a model. Usually involves deleting a column, |
| 336 | but for M2Ms may involve deleting a table. |
| 337 | """ |
| 338 | # M2M fields are a special case |
| 339 | if field.many_to_many: |
| 340 | # For implicit M2M tables, delete the auto-created table |
| 341 | if field.remote_field.through._meta.auto_created: |
| 342 | self.delete_model(field.remote_field.through) |
| 343 | # For explicit "through" M2M fields, do nothing |
| 344 | elif ( |
| 345 | # Primary keys, unique fields, indexed fields, and foreign keys are |
| 346 | # not supported in ALTER TABLE DROP COLUMN. |
| 347 | not field.primary_key |
| 348 | and not field.unique |
| 349 | and not field.db_index |
| 350 | and not (field.remote_field and field.db_constraint) |
| 351 | ): |
| 352 | super().remove_field(model, field) |
| 353 | # For everything else, remake. |
| 354 | else: |
| 355 | # It might not actually have a column behind it |
| 356 | if field.db_parameters(connection=self.connection)["type"] is None: |
| 357 | return |
| 358 | self._remake_table(model, delete_field=field) |
| 359 | |
| 360 | def _alter_field( |
| 361 | self, |
nothing calls this directly
no test coverage detected