# AttributeError: 'Query' 对象没有属性 'default'。

- **ID:** `python/fastapi-attribute-error-no-attribute-query`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 Pydantic v2 / FastAPI 版本中使用了已重命名的参数，或错误地将 `Query()` 与 `Annotated` 混用。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 0.95.x | active | — | — |
| 0.100.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Use the modern form: `q: Annotated[str | None, Query(max_length=50)] = None`
   ```
2. **** (90% 成功率)
   ```
   Or the older positional style: `q: str = Query(None, max_length=50)` (no `default=` keyword).
   ```

## 无效尝试

- **** — Downgrade breaks Pydantic v2 compatibility and other features. (80% 失败率)
- **** — Fragile across versions and breaks OpenAPI generation. (90% 失败率)
