如何使用django删除表中的所有数据 [英] How to remove all of the data in a table using django

查看:2145
本文介绍了如何使用django删除表中的所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题:


  1. 如何删除django中的表

  2. 如何删除表
  3. 中的所有数据
  1. how to delete the table in django
  2. how to remove all of the data in table

这是我的代码,但不成功:

this is my code, but not successful :

Reporter.objects.delete()


推荐答案

在经理里面:

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)

这篇关于如何使用django删除表中的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆