# AttributeError: 类型对象 'User' 没有属性 'Config'。您是想找 'model_config' 吗？

- **ID:** `python/pydantic-model-config-attribute-error`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

将 Pydantic v1 中使用内部 class Config 的代码复制到了 v2 项目中。v2 中配置通过 model_config 类属性和 ConfigDict 设置。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   from pydantic import BaseModel, ConfigDict

class User(BaseModel):
    model_config = ConfigDict(extra='forbid', frozen=True)
    name: str
   ```
2. **** (85% 成功率)
   ```
   pip install bump-pydantic
bump-pydantic ./src
   ```

## 无效尝试

- **** — Pydantic v2 ignores the inner Config class entirely; settings silently have no effect and behavior diverges. (80% 失败率)
- **** — Breaks other v2-only dependencies and pydantic-core bindings; causes cascading import errors across the project. (65% 失败率)
