Asked By – zjm1126
I have two questions:
- How do I delete a table in Django?
- How do I remove all the data in the table?
This is my code, which is not successful:
Now we will see solution for issue: 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)
This question is answered By – Tiago
This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0