What do you want to save?
Add Code snippet
New code examples
-
Other 2022-03-01 16:45:21
how to write manual querry in drf
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",... Add solution -
SQL 2022-01-29 12:21:34
django count sql queries
>>> from django.conf import settings >>> settings.DEBUG = True >>> from django.db import connection >>> Model.objects.count() >>> # python 3 uses print() >>> print(len(connection.queries)) 1 Add solution -
Other 2021-11-15 19:02:11
duplicate key value violates unique constraint "django_migrations_pkey"
from django.db import connections query = "SELECT setval('django_migrations_id_seq', (SELECT MAX(id) FROM django_migrations))" cursor = connections['default'].cursor() cursor.execute(query) row = cursor.fetchone() Add solution -
Shell/Bash 2021-11-10 03:53:14
How can I see the raw SQL queries 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 ... Add solution -
Python 2021-10-13 00:03:06
data don't retrieve from database view in django
#import library from django.db import connection #Create the cursor cursor = connection.cursor() #Write the SQL code sql_string = 'SELECT * FROM myview' #Execute the SQL cursor.execute(sql_string) result = cursor.fetchall() Add solution
Best helpers
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5