i have a question,
is it possible to wrap a SQL command on Django Command ?
because i have this SQL, that need to be executed during deploy
update foo set bar = 'baz'
Use:
from django.db import connection def my_custom_sql(self): with connection.cursor() as cursor: cursor.execute("UPDATE bar SET foo = 1 WHERE baz = %s", [self.baz]) cursor.execute("SELECT foo FROM bar WHERE baz = %s", [self.baz]) row = cursor.fetchone() return row
Ref: https://docs.djangoproject.com/en/3.1/topics/db/sql/#executing-custom-sql-directly
1.4m articles
1.4m replys
5 comments
56.9k users