[英]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.