开发者

error with django model query

I encountered an error when doing the following retrieval:

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"

query:

    statusIn = status.objects.get(pid=12345,phase='crawling')

Error:

django.db.utils.DatabaseError: current transaction is aborted, commands ignored
until end of transaction block

Does anyone knows whats the reason?

EDIT:

In my previous section of my code, I have an exception when inserting an entry to another table, but i caught the exception:

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')
      开发者_JS百科      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


Django stats a database transaction for your view. So when you catch the exception, it means the transaction is in a failed state and you can't run any more SQls. You should really try to figure what the actual problem is when it fails either in your post.save or blogContent.save methods. If you really don't care (since you just catch the exception and continue), you should manage transactions yourself. See the docs for help on this:

  • Managing database transactions
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜