How to remove all of the data in a table using Django How to remove all of the data in a table using Django python python

How to remove all of the data in a table using Django


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 want to remove all the data from all your tables, you might want to try the command python manage.py flush. This will delete all of the data in your tables, but the tables themselves will still exist.

See more here: https://docs.djangoproject.com/en/1.8/ref/django-admin/