[Solved]-Can you run a raw MySQL query in Django without a model?

20👍

Yes, you can query the database table without model by using connection cursor

from django.db import connection

def my_custom_sql(self):
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM table_name where id=1")
    row = cursor.fetchall()
    return row

Leave a comment