Delete data from database
Following methods allow you to delete data from the database.
-
delete(each: bool = False, **kwargs) -> int -
ModelModel.delete()method
-
QuerysetProxyQuerysetProxy.remove()methodQuerysetProxy.clear()method
delete
delete(each: bool = False, **kwargs) -> int
QuerySet level delete is used to delete multiple records at once.
You either have to filter the QuerySet first or provide a each=True flag to delete
whole table.
If you do not provide this flag or a filter a QueryDefinitionError will be raised.
Return number of rows deleted.
| Python | |
|---|---|
1 | |
Model methods
Each model instance have a set of methods to save, update or load itself.
delete
You can delete model instance by calling delete() method on it.
Tip
Read more about delete() method in models methods
QuerysetProxy methods
When access directly the related ManyToMany field as well as ReverseForeignKey
returns the list of related models.
But at the same time it exposes subset of QuerySet API, so you can filter, create, select related etc related models directly from parent model.
remove
Removal of the related model one by one.
Removes the relation in the database.
If you specify the keep_reversed flag to False ormar will also delete the related model from the database.
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 10 | |
clear
Removal of all related models in one call.
Removes also the relation in the database.
If you specify the keep_reversed flag to False ormar will also delete the related model from the database.
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |