I have two questions:
This is my code, which is not successful:
Reporter.objects.delete()
Delete a Record of a Model Using the delete() Method in Django. All the model objects or instances in Django have a delete() method, which can be used to delete that record. Now, this delete() method can be also be used to delete a single record and a bunch of them.
This method will validate all fields on your model. The optional exclude argument lets you provide a set of field names to exclude from validation. It will raise a ValidationError if any fields fail validation. The second step full_clean() performs is to call Model.clean() .
The Manager is the main source of QuerySets for a model. For example, Blog.objects.all() returns a QuerySet that contains all Blog objects in the database.
Inside a manager:
def delete_everything(self): Reporter.objects.all().delete() def drop_table(self): cursor = connection.cursor() table_name = self.model._meta.db_table sql = "DROP TABLE %s;" % (table_name, ) cursor.execute(sql)
As per the latest documentation, the correct method to call would be:
Reporter.objects.all().delete()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With