简体   繁体   English

django-当前事务中止,命令被忽略,直到事务块结束

[英]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 我有这段代码,一旦捕获到IntegrityError,我就会收到此错误: 当前事务中止,命令被忽略,直到事务块结束

why is this? 为什么是这样? if i delete the context_instance part, then i am getting again the page but without any media access. 如果我删除context_instance部分,那么我将再次获得该页面,但没有任何媒体访问权限。 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. 顺便说一句 :我正在使用django1.4和postgresql。 and User is django's auth user 并且User是django的身份验证用户

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: 使用user_create启动事务,然后再次执行此操作会导致未提交事务的错误。您必须在user_create之后提交(结束)事务,如下所示:

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))

Are you using a default database or couple database. 您使用的是默认数据库还是情侣数据库。 it's recommended to use db_manager() to specify the database. 建议使用db_manager()指定数据库。 db_manager() returns a copy of the manager bound to the database you specify. db_manager()返回绑定到您指定的数据库的管理器的副本。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 InternalError:当前事务中止,命令被忽略,直到事务块结束 - InternalError: current transaction is aborted, commands ignored until end of transaction block DatabaseError:当前事务被中止,在事务块结束之前忽略命令? - DatabaseError: current transaction is aborted, commands ignored until end of transaction block? django reg extension-当前事务中止,命令被忽略,直到事务块结束 - django reg extend - current transaction is aborted, commands ignored until end of transaction block Django:通过添加m2m导致“当前事务中止,命令被忽略,直到事务块结束” - Django: Added m2m via through causes 'current transaction is aborted, commands ignored until end of transaction block' psycopg2.errors.InFailedSqlTransaction:当前事务被中止,命令被忽略直到事务块结束 - psycopg2.errors.InFailedSqlTransaction: current transaction is aborted, commands ignored until end of transaction block 错误:当前事务中止,创建新记录时命令被忽略,直到事务块结束 - Error: current transaction is aborted, commands ignored until end of transaction block while creating a new record SQLAlchemy + postgres:(InternalError)当前事务中止,命令被忽略,直到事务块结束 - SQLAlchemy + postgres : (InternalError) current transaction is aborted, commands ignored until end of transaction block DatabaseError:当前事务中止,命令被忽略,直到事务块结束-在隐身模式下,但正常情况下没有错误 - DatabaseError: current transaction is aborted, commands ignored until end of transaction block - in incognite mode but no error in normal 如何调试:内部错误当前事务被中止,命令被忽略直到事务块结束 - How to debug: Internal Error current transaction is aborted, commands ignored until end of transaction block 使用 Python 连接到 Redshift 数据 - 错误:当前事务被中止,命令被忽略,直到事务块结束 - Connecting to Redshift Data Using Python - Error: current transaction is aborted, commands ignored until end of transaction block
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM