Primary key requirement in raw SQL complicates the query in Django
You should use custom SQL instead of Manager.raw()
method:
from django.db import connection
cursor = connection.cursor()
cursor.execute('SELECT max(value) FROM mytable')
max_value = cursor.fetchone()[0]
U can use
ModelName.objects.raw('SELECT 1 as id , max(value) FROM mytable')