Doug Blank wrote:

> > Plutocrat.objects.all().delete()
>
> I found that quite slow. If you want to stay DB agnostic, I came up with this:
>
>    from django.db import connection, transaction
>    models = [Person, User, ...]
>    cursor = connection.cursor()
>    flush_tables = []
>    for model in models:
>        flush_tables.append(model._meta.db_table)
>    statements = connection.ops.sql_flush(no_style(),
>                                flush_tables,
>                                connection.introspection.sequence_list())
>    for statement in statements:
>        cursor.execute(statement)
>        transaction.commit_unless_managed()
>
> I don't know of any bad side effects...

And why isn't that all inside .all().delete()? I thought the point of
the builder().notation() was to defer the actual SQL generation until
the end, where you can optimize it.

Anyway thanks all & good thread; I will go with the slow option
because it's just test-side!

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to