执行以下检索时遇到错误:
class status(models.Model):
pid = models.IntegerField()
phase = models.TextField()
rejected = models.IntegerField()
accepted = models.IntegerField()
type = models.IntegerField(default=1)
date = models.DateTimeField(primary_key = True)
time_taken = models.IntegerField(null = True)
class Meta:
db_table = "crawl_status_ss"
查询:
statusIn = status.objects.get(pid=12345,phase='crawling')
错误:
django.db.utils.DatabaseError: current transaction is aborted, commands ignored
until end of transaction block
有谁知道原因是什么?
编辑:
在我的上一部分代码中,将条目插入另一个表时出现异常,但我发现异常:
for entry in blogEntries:
link = entry['link'].encode('utf-8')
title = entry['title'].encode('utf-8')
date1 = entry['date'][:10].encode('utf-8')
content = entry['content'].encode('utf-8')
try:
post = postTitle(site_id=url,post_url=link,post_title=title)
post.save()
postId = post.post_id
hashString = getMD5Hash(content)
blogContent = postContent(post_content=content,post_id=post,hash=hashString,site_id = url,post_date=date1)
blogContent.save()
except:
print 'Error:' + str(sys.exc_value)
continue
答案 0 :(得分:2)
Django统计视图的数据库事务。因此,当您捕获异常时,这意味着事务处于失败状态,您无法再运行SQls。您应该在post.save
或blogContent.save
方法中尝试确定实际问题是什么时候失败。如果您真的不在乎(因为您只是捕获异常并继续),您应该自己管理事务。请参阅文档以获取相关帮助: