系统检查发现3个问题(0个沉默)

时间:2017-08-11 17:00:14

标签: django sqlite django-models fedora-25

我的model.py .i的问题是什么可以尝试一切都没有发生。我认为我以正确的方式定义了我的外键。可能是我的定义有问题或我必须使用{{1}在我的foreginkey中或者会产生什么影响。欢迎任何贡献。

memberid.user

这是我的model.py代码

Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x7f6a926d69b0>
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 405, in check
    raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
tithe.tithe.memberid: (fields.E300) Field defines a relation with model 'memberid', which is either not installed, or is abstract.
tithe.tithe.memberid: (fields.E307) The field tithe.tithe.memberid was declared with a lazy reference to 'tithe.memberid', but app 'tithe' doesn't provide model 'memberid'.
tithe.tithe: (models.E012) 'unique_together' refers to the non-existent field 'IntegerField'.

System check identified 3 issues (0 silenced).
Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x7f3d3ccdc9b0>
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 405, in check
    raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
tithe.tithe.memberid: (fields.E300) Field defines a relation with model 'User', which is either not installed, or is abstract.
tithe.tithe.memberid: (fields.E307) The field tithe.tithe.memberid was declared with a lazy reference to 'tithe.user', but app 'tithe' doesn't provide model 'user'.
tithe.tithe: (models.E012) 'unique_together' refers to the non-existent field 'IntegerField'.

3 个答案:

答案 0 :(得分:1)

以下一行

memberid = models.ForeignKey('User')

造成了这个问题。您必须将User对象传递给它。

导入User模型。

from django.contrib.auth.models import User

然后

memberid = models.ForeignKey(User)

答案 1 :(得分:1)

前两个警告是因为Django找不到您在'User'外键中引用的模型memberid

我建议您使用settings.AUTH_USER_MODEL来引用用户模型。无论您是否拥有自定义用户模型,这都将有效。

memberid = models.ForeignKey(settings.AUTH_USER_MODEL)

有关referencing the user model的更多信息,请参阅文档。

请注意,最好为您的字段member调用名称。这样,相关实例将为member,相关ID将为member_id。目前,相关实例为memberid,相关ID为memberid_id

最后警告是因为您在模型中没有字段IntegerField。如果您希望receitcode字段本身唯一,请移除unique_together行并将字段更改为:

receitcode = models.CharField(max_length=45, unique=True)

答案 2 :(得分:0)

您的ForeignKey需要引用具体模型或抽象模型。由于您使用字符串引用(这意味着模型是抽象的),您需要通过声明abstract = True

来声明类Meta:as abstract

当模型作为具体模型被子类化并且与抽象模型的app_label无关时,解析这种在抽象模型上定义的关系:

以下信息来自Django文档https://docs.djangoproject.com/en/1.11/ref/models/fields/

 products/models.py
from django.db import models

class AbstractCar(models.Model):
manufacturer = models.ForeignKey('Manufacturer', on_delete=models.CASCADE)

# This is what you need to add
class Meta:
    abstract = True