MCPcopy
hub / github.com/django/django / DeleteModel

Class DeleteModel

django/db/migrations/operations/models.py:382–416  ·  view source on GitHub ↗

Drop a model's table.

Source from the content-addressed store, hash-verified

380
381
382class DeleteModel(ModelOperation):
383 """Drop a model's table."""
384
385 category = OperationCategory.REMOVAL
386
387 def deconstruct(self):
388 kwargs = {
389 "name": self.name,
390 }
391 return (self.__class__.__qualname__, [], kwargs)
392
393 def state_forwards(self, app_label, state):
394 state.remove_model(app_label, self.name_lower)
395
396 def database_forwards(self, app_label, schema_editor, from_state, to_state):
397 model = from_state.apps.get_model(app_label, self.name)
398 if self.allow_migrate_model(schema_editor.connection.alias, model):
399 schema_editor.delete_model(model)
400
401 def database_backwards(self, app_label, schema_editor, from_state, to_state):
402 model = to_state.apps.get_model(app_label, self.name)
403 if self.allow_migrate_model(schema_editor.connection.alias, model):
404 schema_editor.create_model(model)
405
406 def references_model(self, name, app_label):
407 # The deleted model could be referencing the specified model through
408 # related fields.
409 return True
410
411 def describe(self):
412 return "Delete model %s" % self.name
413
414 @property
415 def migration_name_fragment(self):
416 return "delete_%s" % self.name_lower
417
418
419class RenameModel(ModelOperation):

Callers 1

test_remove_relationsMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_remove_relationsMethod · 0.72