[Answered ]-Best way to save Raw SQL queries in Django

1👍

You can try this:

from django.db import connection

cursor = connection.cursor()

raw_query = "write your query here"
cursor.execute(raw_query)

You can also run raw queries for models. eg. MyModel.objects.raw('my query').

Read Performing raw SQL queries | Django documentation | Django for more.

Leave a comment