[Answered ]-Execute raw SQL after connect to database

1👍

Just visit the docs here.

It was I think the second match on google with “Django ORM”.

EDIT See comments

If you look at this Django page you see that MySQLdb (the underlying layer) also accepts an init_command option which is run immediately after a connection is established. That’s a feature of MySQLdb, and not so much of Django itself.

1👍

If you are using django >= 1.2:

from django.db import connection, transaction

query = "SELECT foo FROM bar;"
connection.cursor().execute(query)
transaction.commit_unless_managed()

Leave a comment