python
data_error
ai_generated
true
字段不存在错误:Book 没有名为 'published_year' 的字段
django.core.exceptions.FieldDoesNotExist: Book has no field named 'published_year'
ID: python/django-query-param-missing
80%修复率
84%置信度
0证据数
2025-12-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
尝试按模型中不存在的字段进行过滤或排序。
English
Attempting to filter or order by a field that doesn't exist on the model.
解决方案
-
90% 成功率
Add the field to model: published_year = models.IntegerField() and run migrations.
-
95% 成功率
Use correct existing field: published_date__year for filtering by year.
无效尝试
常见但无效的做法:
-
70% 失败
Adding a property named published_year to model doesn't make it queryable.
-
50% 失败
Using annotate with wrong name still raises FieldDoesNotExist.