Performing raw SQL queries
Performing raw SQL queries
When the model query APIs don’t go far enough, you can fall back to writing raw SQL. Django gives you two ways of performing raw SQL queries: you can use Manager.raw()
to perform raw queries and return model instances, or you can avoid the model layer entirely and execute custom SQL directly.
Warning
You should be very careful whenever you write raw SQL. Every time you use it, you should properly escape any parameters that the user c