Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 扩展django管理日志,导致where子句中出现未知列_Python_Mysql_Sql_Django - Fatal编程技术网

Python 扩展django管理日志,导致where子句中出现未知列

Python 扩展django管理日志,导致where子句中出现未知列,python,mysql,sql,django,Python,Mysql,Sql,Django,我需要在django站点上存储各种操作的审计日志,因此我扩展了标准日志模型,以容纳我们需要存储的额外信息 models.py from django.contrib.admin.models import LogEntry from django.db import models from django.utils.encoding import smart_text from django.utils.translation import ugettext_lazy as _ from co

我需要在django站点上存储各种操作的审计日志,因此我扩展了标准日志模型,以容纳我们需要存储的额外信息

models.py

from django.contrib.admin.models import LogEntry
from django.db import models
from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _

from consoles.models import Client, Console

class AuditLogEntryManager(models.Manager):
    def log_action(self, user_id, content_type_id, object_id, object_repr,
                   action_flag, change_message='', client=None, console=None):
        e = self.model(
            None, None, user_id, content_type_id, smart_text(object_id),
            object_repr[:200], action_flag, change_message, client, console
        )
        e.save()


class AuditLog(LogEntry):
    """
    Providing additional properties to the django admin log.
    """

    client = models.ForeignKey(Client, blank=True, null=True, default=None)
    console = models.ForeignKey(Console, blank=True, null=True, default=None)

    objects = AuditLogEntryManager()

    class Meta:
        verbose_name = _('log entry')
        verbose_name_plural = _('log entries')
        db_table = 'django_admin_log'
        ordering = ('-action_time',)
我已经设置了一个类来记录操作

class Audit(object):
    ADDITION = ADDITION
    CHANGE = CHANGE
    DELETION = DELETION

    def ct(self, object):
        return ContentType.cache.get(object)

    def logged_in(self, user, console=None, client=None, message=None):
        if not message:
            message = _("{} logged in".format(user.username))
        object_repr = u'(%s) %s' % (user.id, user.username)

        AuditLog.objects.log_action(
            user_id=user.id,
            content_type_id=self.ct(user).pk,
            object_id=user.pk,
            object_repr=object_repr,
            action_flag=ADDITION,
            change_message=message, client=client, console=console
        )
当我尝试在用户成功登录后调用
logged\u in(request.user)
时,我得到一个SQL错误
OperationalError:(1054,“where子句”中的未知列'django\u admin\u log.logentry\u ptr\u id')

我假设这与我对
django\u admin\u log
表的扩展有关,但我对SQL不是很在行。有人能解释一下这个问题,也许能提供一个更好的解决方案吗