                          "relation and therefore cannot be used for reverse "
                          "querying. If it is a GenericForeignKey, consider "
                          "adding a GenericRelation." % name
                      )
                  model = field.model._meta.concrete_model
              else:
                  # We didn't find the current field, so move position back
                  # one step.
                  pos -= 1
                  if pos == -1 or fail_on_missing:
 
</s> remove from django.db.models.functions import Lower
 </s> add from django.db.models.functions import Length, Lower
                try:
                    model = field.model._meta.concrete_model
                except AttributeError:
                    # QuerySet.annotate() may introduce fields that aren't
                    # attached to a model.
                    model = None
                          "relation and therefore cannot be used for reverse "
                          "querying. If it is a GenericForeignKey, consider "
                          "adding a GenericRelation." % name
                      )
                try:
                    model = field.model._meta.concrete_model
                except AttributeError:
                    # QuerySet.annotate() may introduce fields that aren't
                    # attached to a model.
                    model = None
              else:
                  # We didn't find the current field, so move position back
                  # one step.
                  pos -= 1
                  if pos == -1 or fail_on_missing:
keep keep keep keep replace keep keep keep keep keep
 Fixed #27800 -- Fixed QuerySet.annotate(Length(...)).distinct() crash. 
django/db/models/sql/query.py