doniyor
doniyor

Reputation: 37846

django - current transaction is aborted, commands ignored until end of transaction block

try: 
   user = User.objects.create_user(_username, _email, pwd)
except IntegrityError, e:
   fail = e.message
   return render_to_response('register.html',{'reg_fail':fail},context_instance=RequestContext(request)) 

I have this code, once i catch the IntegrityError, i am getting this error: current transaction is aborted, commands ignored until end of transaction block

why is this? if i delete the context_instance part, then i am getting again the page but without any media access. I am stuck, i want just to register a user or if integrityError, then render to register page with error message.

by the way: i am using django1.4 and postgresql. and User is django's auth user

Upvotes: 1

Views: 1012

Answers (2)

drabo2005
drabo2005

Reputation: 1096

Are you using a default database or couple database. it's recommended to use db_manager() to specify the database. db_manager() returns a copy of the manager bound to the database you specify.

User.objects.db_manager(’new_users’).create_user(...)

Upvotes: 0

adamr
adamr

Reputation: 750

With user_create you start transaction, and doing this again cause the error of not commited transaction.You have to commit(end) your transaction after user_create as follow:

try: 
   user = User.objects.create_user(_username, _email, pwd)
   user.full_clean()
   user.save()
except IntegrityError, e:
   fail = e.message
   return render_to_response('register.html',{'reg_fail':fail},context_instance=RequestContext(request))

Upvotes: 1

Related Questions