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

后端 未结 8 1762
执笔经年
执笔经年 2020-12-12 21:12

I have two questions:

  1. How do I delete a table in Django?
  2. How do I remove all the data in the table?

This is my code, which is not succe

8条回答
  •  温柔的废话
    2020-12-12 21:57

    There are a couple of ways:

    To delete it directly:

    SomeModel.objects.filter(id=id).delete()
    

    To delete it from an instance:

    instance1 = SomeModel.objects.get(id=id)
    instance1.delete()
    

    // don't use same name

提交回复
热议问题