![](/img/trans.png)
[英]Django SystemCheckError: System check identified some issues:
[英]Django model field name “check” raises SystemCheckError
Django文檔指出,模型字段名稱只有兩個限制
但是,給出以下示例,看起來我不能將字段名稱check
用作ForeignKey。
class Check(models.Model):
name = models.CharField(max_length=100)
class MyModel(models.Model):
# this works fine
#check = models.BooleanField()
# this breaks
check = models.ForeignKey(Check, on_delete=models.PROTECT, related_name='+')
這是錯誤:
$ python manage.py check
SystemCheckError: System check identified some issues:
ERRORS:
myapp.MyModel: (models.E020) The 'MyModel.check()' class method is currently overridden by <django.db.models.fields.related_descriptors.ForwardManyToOneDescriptor object at 0x03A818D0>
文檔是否錯誤,或者我做錯了什么?
編輯:忘記提及此項目正在使用Python 2和Django 1.11
我在Django文檔( https://docs.djangoproject.com/en/2.2/ref/checks/#system-check-framework )中找到了系統檢查框架
在django的系統檢查期間調用的檢查字段將引發SystemCheckError。
它發生在django的Basecommand
( https://github.com/django/django/blob/1e87c9fe71703fab23039aa63fafe4f6aac98bbc/django/core/management/base.py#L148 )
1. ``django-admin`` or ``manage.py`` loads the command class
and calls its ``run_from_argv()`` method.
2. The ``run_from_argv()`` method calls ``create_parser()`` to get
an ``ArgumentParser`` for the arguments, parses them, performs
any environment changes requested by options like
``pythonpath``, and then calls the ``execute()`` method,
passing the parsed arguments.
3. The ``execute()`` method attempts to carry out the command by
calling the ``handle()`` method with the parsed arguments; any
output produced by ``handle()`` will be printed to standard
output and, if the command is intended to produce a block of
SQL statements, will be wrapped in ``BEGIN`` and ``COMMIT``.
4. If ``handle()`` or ``execute()`` raised any exception (e.g.
``CommandError``), ``run_from_argv()`` will instead print an error
message to ``stderr``.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.