🧩 Pydantic v1 vs Pydantic v2
FastAPI is compatible with both Pydantic v1 and Pydantic v2.
Depending on the version of FastAPI you are using, you may encounter minor differences in method names and configuration options.
🔄 Key Changes in Pydantic v2
The most significant updates include:
The
.dict()method has been replaced with.model_dump()The
schema_extraattribute within theConfigclass has been renamed tojson_schema_extraOptional fields must be explicitly initialized with
NoneExample:
id: Optional[int] = None