如何使用Django的ORM TRUNC TABLE TABLE? [英] How to TRUNCATE TABLE using Django's ORM?
本文介绍了如何使用Django的ORM TRUNC TABLE TABLE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要清空数据库表,我使用此SQL查询:
To empty a database table, I use this SQL Query:
TRUNCATE TABLE `books`
如何使用Django的模型和ORM截断表?
How to I truncate a table using Django's models and ORM?
我已经尝试了这个,但它不起作用:
I've tried this, but it doesn't work:
Book.objects.truncate()
推荐答案
与ORM最接近的是 Book .objects.all()。delete()
。
尽管如此,截断可能会更快,但ORM也会追逐关闭外键引用并删除其他表中的对象。
There are differences though: truncate will likely be faster, but the ORM will also chase down foreign key references and delete objects in other tables.
这篇关于如何使用Django的ORM TRUNC TABLE TABLE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文