I found a solution to this problem by setting DISABLE_SERVER_SIDE_CURSORS to True:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"USER": "mydatabaseuser",
...
"DISABLE_SERVER_SIDE_CURSORS": True, # This line
},
}
https://docs.djangoproject.com/en/5.2/ref/settings/#std-setting-DATABASE-DISABLE_SERVER_SIDE_CURSORS