Reopen https://code.djangoproject.com/ticket/16427

Hi all ,

I want everyone’s view regarding this topic of adding truncate on django ORM.

https://code.djangoproject.com/ticket/16427

Given that the ticket in question predates the migrations framework, maybe - though it would not be part of the ORM directly, but rather a migration action, if you ask me.

That said, is it worth abstracting this across database backends rather than just having people use the raw SQL? If I recall right, there’s some nasty locking tradeoffs in different backends with truncate. Might be worth it for test usage, though.

1 Like

I also think it’s too nuanced to add to Django. The MariaDB TRUNCATE documentation lists many tradeoffs. For example, it implicitly commits the current transaction, you can’t truncate a table referenced in a FK constraint, and if you do truncate a table its autoincrement is reset.

If you are in the narrow set of use cases where it makes sense to use TRUNCATE, it’s not much work to format the SQL like f"TRUNCATE TABLE {Model._meta.db_table}").

1 Like