Answers for "raw query in django"

0

raw query in django

from django.db import connection

sql = 'SELECT * FROM db1.a AS a
       JOIN db2.b AS b 
       ON b.some_id = a.id
       WHERE a.name = %s'
cursor = connection.cursor()
try:
      cursor.execute(sql, ['localhost'])
      row = cursor.fetchall()
except Exception as e:
      cursor.close
Posted by: Guest on June-01-2020
0

How can I see the raw SQL queries Django

$ python manage.py sqlmigrate <app_name> <migration_number>

#Ex: $ python manage.py sqlmigrate polls 0001
# It will show the sql quires of specific migrations
Posted by: Guest on July-23-2021
0

django swlite queries

>>> Entry.objects.filter(pub_date__lte='2006-01-01')
Posted by: Guest on October-26-2020

Python Answers by Framework

Browse Popular Code Answers by Language