What is the fastest way to truncate a table in the Django ORM based on the database type in a view? I know you can do this for example
Books.objects.all().delete()
but with tables containing millions of rows it is very slow. I know it is also possible to use the cursor and some custom SQL
from django.db import connection
cursor = connection.cursor()
cursor.execute("TRUNCATE TABLE `books`")
However, the TRUNCATE command does not work with SQLite. And if the database moves to another db type, I need to account for that.
Any ideas? Would it be easier to just drop the table and recreate in my view?