stupidkid
stupidkid

Reputation: 410

TransactionManagementError?

Hello thanks for reading. I am doing a quick site in Django and I have a very simple update statement in raw SQL I am making to my Postgres database. Something in here is making trouble:

from django.http import HttpResponse
from django.db import connection, transaction

def rsvp_update(request, rsvp_id, status):
  cursor = connection.cursor()
  cursor.execute("UPDATE public.rsvp SET status=%s WHERE rsvp_id = %s", [status, rsvp_id])
  transaction.commit()
  return HttpResponse('okay')

I am getting an error that says "TransactionManagementError at [URL] This code isn't under transaction management". Any ideas?

Upvotes: 1

Views: 2714

Answers (1)

wRAR
wRAR

Reputation: 25569

You need to use the commit_manually decorator for the code where you manage transactions manually.

Upvotes: 6

Related Questions