Haystack SearchFieldError : The model 'None' combined with model_attr <attr_name> returned None

Haystack SearchFieldError : The model 'None' combined with model_attr <attr_name> returned None

在 运行 rebuild_index,来自其他应用程序的对象正在被索引,但在一个应用程序上发生 SearchFieldError。

这是我的 models.py 相关应用程序:

class Doctor(models.Model):
    SPECIALTY_CHOICES = (
        ('Pediatric Physiotherapist', 'Pediatric Physiotherapist')
    )
    user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE)
    doctorName = models.CharField(max_length=100)
    doctorQual = models.CharField(max_length=500)
    doctorSpecial = models.CharField(choices=SPECIALTY_CHOICES, default='', max_length=50)
    doctorSummary = models.CharField(max_length=1000)
    doctorLocation = models.CharField(max_length=100, default=' ', null=True, blank=True)
    slug = models.SlugField(null=True, blank=True)
    city = models.CharField(max_length = 100, null=True, blank=True)

    def __str__(self):
        return self.doctorName

    #   save method overridden to generate slug for each object

    def save(self, *args, **kwargs):
        self.slug = slugify(self.doctorName)
        super(Doctor, self).save(*args, **kwargs)

    def get_absolute_url(self):
        return "/doctor/doc_detail_page/%i" % self.id

    def get_summary(self):
        return self.doctorSummary

    class Meta:
        permissions = (
            ("can_create", "yoyo"),
        )

我的search_indexes.py是:

from haystack import indexes
from .models import Doctor


class DoctorIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    doctorName = indexes.CharField(model_attr='doctorName')
    doctorSummary = indexes.CharField(model_attr='doctorSummary')
    doctorSpecial = indexes.CharField(model_attr='doctorSpecial', faceted=True)
    doctorLocation = indexes.CharField(model_attr='doctorLocation',faceted=True)
    content_auto_doc = indexes.EdgeNgramField(model_attr='doctorName')     # this field is for auto complete

    def get_model(self):
        return Doctor

    def index_queryset(self, using=None):
        return self.get_model().objects.all()

这些是版本:

我在这里做错了什么。请帮忙!!

尝试在您的模型中为您遇到错误的属性添加 default=' ' 要么 尝试为 DoctorIndex 中出现错误的属性添加 null=True 不久前它对我有用 例如

example_field = indexes.CharField(model_attr='example_field', null=True)