我有一个运行良好的 django 应用程序,突然之间似乎有些东西坏了。
class ClosedUserGroup(models.Model):
""" Preset definitions for ClosedUserGroup:
"""
is_active = models.BooleanField(default=True)
is_deleted = models.BooleanField(default=False)
created_at = models.DateTimeField(
auto_now=True,
auto_now_add=True,
null=True,
default='2013-08-15 13:37:13.370030'
)
name = models.CharField(max_length=256, default='<MISSING:CUG_NAME')
description = models.CharField(max_length=256)
class Partner(models.Model):
id = models.IntegerField(primary_key=True)
is_active = models.BooleanField(default=True)
is_deleted = models.BooleanField(default=False)
created_at = models.DateTimeField(
auto_now=True,
auto_now_add=True,
null=True,
default=datetime.datetime.now()
)
name = models.CharField(max_length=256, default='<MISSING:PARTNERNAME>')
class PartnerCug(models.Model):
""" Partner to ClosedUserGroup relation
"""
is_active = models.BooleanField(default=True)
is_deleted = models.BooleanField(default=False)
created_at = models.DateTimeField(
auto_now=True,
auto_now_add=True,
null=True,
default='2013-08-15 13:37:13.370030'
)
partner = models.ForeignKey(Partner)
cug = models.ForeignKey(ClosedUserGroup)
class Account(models.Model):
"""
Account:
TODO:DESCRIPTION
"""
id = models.IntegerField(primary_key=True)
is_active = models.BooleanField(default=True)
is_deleted = models.BooleanField(default=False)
created_at = models.DateTimeField(
auto_now=True,
auto_now_add=True,
null=True,
default=datetime.datetime.now()
)
number = models.CharField(max_length=64)
submitted_by = models.ForeignKey(
Partner,
db_column='submitted_by'
)
在 django shell 中,以下命令运行成功并返回结果 1:
from myapp.models import Account
account_object = Account.objects.filter(id=1)
account_object.filter(account__submitted_by__partnercug__cug=3).count()
然而,在 django 本身,我有这个功能
def get_other_accounts():
"""get total accounts"""
account_object = Account.objects.filter(id=1)
total_accounts = account_object.filter(account__submitted_by__partnercug__cug=3).count()
然而,这会因错误DatabaseError: current transaction is aborted, commands ignored until end of transaction block
而失败,它指向该函数的最后一行。所以它的工作 django shell 但不是来自网络应用程序。