# pydantic.errors.PydanticUserError: `model_config` 不能用作模型字段名。请使用 `model_config` 作为模型配置。

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

## 根因

v2 模型中定义了名为 `model_config` 的属性（通常从 v1 代码移植而来），而 Pydantic 保留该名称用于配置。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Rename the field and add an alias: `class M(BaseModel):
    model_config = ConfigDict(populate_by_name=True)
    cfg: dict = Field(alias='model_config')`
   ```
2. **** (90% 成功率)
   ```
   Use `Field(alias='model_config')` and read via `obj.cfg`; update all callers to use the new attribute name.
   ```

## 无效尝试

- **** — Renaming only in the class but not in callers leaves `AttributeError` at runtime when code reads `obj.model_config`. (60% 失败率)
- **** — Adding `class Config` alongside `model_config` triggers a second PydanticUserError about mixing v1 and v2 config styles. (90% 失败率)
