python data_error ai_generated true

django.core.exceptions.FieldError: 无法将关键字'name'解析为字段。选择有:id, created_at

django.core.exceptions.FieldError: Cannot resolve keyword 'name' into field. Choices are: id, created_at

ID: python/django-queryset-order-by-error

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2024-01-05首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

在order_by()中使用模型上不存在的字段。

English

Using order_by() with a field that does not exist on the model.

generic

解决方案

  1. 95% 成功率
    Check model fields and use correct field: MyModel.objects.order_by('created_at')
  2. 90% 成功率
    Use related field with double underscore: order_by('related__field')

无效尝试

常见但无效的做法:

  1. 70% 失败

    May not provide desired ordering.

  2. 80% 失败

    Hides error, may break functionality.