Drop a model's table.
| 380 | |
| 381 | |
| 382 | class 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 | |
| 419 | class RenameModel(ModelOperation): |
no outgoing calls