MCPcopy
hub / github.com/django/django / remove_field

Method remove_field

django/db/backends/sqlite3/schema.py:333–358  ·  view source on GitHub ↗

Remove a field from a model. Usually involves deleting a column, but for M2Ms may involve deleting a table.

(self, model, field)

Source from the content-addressed store, hash-verified

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,

Callers

nothing calls this directly

Calls 3

delete_modelMethod · 0.95
_remake_tableMethod · 0.95
db_parametersMethod · 0.45

Tested by

no test coverage detected