Pydantic v1 to v2 Migration Guide: What Changed
Migrating from Pydantic v1 to v2: renamed methods, validators, model config, BaseSettings, Optional fields, pydantic.v1, bump-pydantic and FastAPI support.
Most of a Pydantic v1 to v2 migration is renaming methods and rewriting validators, but the parts that cause bugs are behaviour changes: Optional fields become required, old Config keys are silently ignored, and numbers are no longer coerced to strings. Pydantic v2 is the current release (2.14.4 on 19 November 2026, requiring Python 3.10 or later), and v1 is still published: 1.10.27 appeared on 29 October 2026.
All the output below was produced by running the same code on Pydantic 1.10.27 (Python 3.12) and Pydantic 2.14.4 (Python 3.14), re-checked on 21 November 2026.
What was renamed
The official migration guide says all non-deprecated BaseModel methods now start with model_, and that the old methods are kept where possible but emit deprecation warnings.
| v1 | v2 | Old name in v2 |
|---|---|---|
.dict() |
.model_dump() |
Works, with a deprecation warning |
.json() |
.model_dump_json() |
Works, but arguments such as indent raise TypeError |
Model.parse_obj(data) |
Model.model_validate(data) |
Works, with a deprecation warning |
Model.parse_raw(text) |
Model.model_validate_json(text) |
Works, with a deprecation warning |
Model.schema() |
Model.model_json_schema() |
Works, with a deprecation warning |
.copy() |
.model_copy() |
Works, with a deprecation warning |
Model.construct() |
Model.model_construct() |
Deprecated |
__fields__ |
model_fields |
Deprecated |
update_forward_refs() |
model_rebuild() |
Deprecated |
from_orm() and orm_mode |
model_validate() with from_attributes=True |
from_orm works, with a warning |
parse_obj_as(T, data) |
TypeAdapter(T).validate_python(data) |
Works, with a deprecation warning |
@validate_arguments |
@validate_call |
Works, with a deprecation warning |
ConstrainedInt and friends |
Annotated[int, Field(ge=0)] |
Removed: PydanticImportError |
__root__ field |
RootModel |
Removed: PydanticUserError |
from pydantic import BaseSettings |
from pydantic_settings import BaseSettings |
PydanticImportError |
The warning class is PydanticDeprecatedSince20, which is a subclass of DeprecationWarning. One difference to expect in any output you compare: .json() produced {"name": "Ada", "age": 36} on v1, while model_dump_json() produces the compact {"name":"Ada","age":36}. The migration guide says so, and that .json(indent=2) can fail with confusing errors. On v2 it fails with TypeError: dumps_kwargs keyword arguments are no longer supported, while model_dump_json(indent=2) returns the indented JSON.
Validators
# v1
from pydantic import BaseModel, validator
class User(BaseModel):
name: str
@validator("name")
def not_empty(cls, v):
if not v.strip():
raise ValueError("empty")
return v# v2
from pydantic import BaseModel, field_validator
class User(BaseModel):
name: str
@field_validator("name")
@classmethod
def not_empty(cls, v: str) -> str:
if not v.strip():
raise ValueError("empty")
return vRunning User(name=" ") gives the error empty on v1 and Value error, empty on v2, so tests that compare messages need updating. @validator still works on v2 but emits PydanticDeprecatedSince20 when the class is defined.
@root_validatorbecomes@model_validator, withmode="before"ormode="after". A mode"after"validator receives the model instance. Keeping@root_validatoron v2 requiresskip_on_failure=True; without it, defining the class raisesPydanticUserError.each_itemis gone. Annotate the item type instead, for examplelist[Annotated[int, Field(ge=0)]].TypeErroris no longer wrapped. ATypeErrorraised inside a validator now propagates instead of becoming aValidationError.@validate_argumentsis@validate_call. Both coerce"3"to3, and invalid input raises aValidationError.
Config
# v1
class User(BaseModel):
class Config:
orm_mode = True
anystr_strip_whitespace = True
# v2
from pydantic import ConfigDict
class User(BaseModel):
model_config = ConfigDict(from_attributes=True, str_strip_whitespace=True)The guide lists the renamed keys, among them orm_mode to from_attributes, anystr_strip_whitespace to str_strip_whitespace, allow_population_by_field_name to populate_by_name, schema_extra to json_schema_extra and validate_all to validate_default. It also lists removed keys such as allow_mutation (use frozen), fields, json_loads, json_dumps and smart_union.
An old class Config does not fail on v2, and its renamed keys do nothing. With anystr_strip_whitespace = True under the old spelling, User(name=" x ").name stayed " x ". Pydantic emits a PydanticDeprecatedSince20 warning that class-based config is deprecated, and a separate UserWarning reading Valid config keys have changed in V2: * 'anystr_strip_whitespace' has been renamed to 'str_strip_whitespace'. A UserWarning is not a DeprecationWarning, so -W error::DeprecationWarning will not catch it.
Behaviour changes to watch
Optionalno longer implies a default.x: Optional[int]is required but may beNone. On v1O()returnedO(x=None); on v2 it raisesx: Field required. Writex: Optional[int] = Nonefor an optional field.- Numbers are not coerced to strings.
name: straccepted1and1.5on v1 (as'1'and'1.5'). On v2 both raiseInput should be a valid string. The migration guide says this coercion is now disabled by default and can be switched on withcoerce_numbers_to_str. Bytes such asb"abc"are still accepted. - Equality is stricter. A model no longer equals a dict containing its data, and models of different types are never equal.
- Serialising nested subclasses now includes only the fields declared on the annotated type.
__root__models becomeRootModel, for exampleRootModel[list[int]]([1, 2]).BaseSettingsmoved topydantic-settings. See python-dotenv vs pydantic-settings.
Tooling
- Move to
pydantic>=2. - Optionally run
bump-pydantic. The migration guide describes it as beta, and PyPI shows its last release, 0.8.0, on 28 December 2023. On a small test model it moved the settings fromclass Configintomodel_config = ConfigDict(from_attributes=True, str_strip_whitespace=True), changed@validatorinto@field_validatorwith@classmethod, and added= Noneto anOptionalfield. It left.dict(),.json()and.parse_obj()calls unchanged, so search for those yourself. Review its diff. - Run your tests with warnings visible:
python -W error -m pytest. Use plain-W error, since the config-key warning above is aUserWarning. See pytest fixtures explained. - Fix what remains, then run a type checker; see Python type checkers compared.
Staying on v1 for now
You can install the last v1 release with pip install "pydantic==1.*". Pydantic v2 also ships the old API as pydantic.v1, and from v1.10.17 that namespace exists inside v1 too, so you can change imports to pydantic.v1 first and upgrade the package afterwards. Two cautions: the migration guide says the pydantic.v1 namespace was removed in Pydantic V3, and FastAPI’s documentation says the Pydantic team stopped supporting Pydantic v1, including pydantic.v1, on Python 3.14 and above. In a quick test on Python 3.14, from pydantic.v1 import BaseModel imported and validated normally with Pydantic 2.14.4 and no warning, even with warnings turned into errors, but treat it as a stopgap rather than a destination.
If you do stay on v1 for now, be on 1.10.27 or later. It was released on 29 October 2026 with fixes for three security issues in v1: quadratic-time validation of timedelta strings and of unique_items lists, and a validation bypass in v1 dataclasses that allow extra data. Four more advisories apply to v2 and are fixed in 2.14.0 and 2.14.2, so on v2 use 2.14.2 or later. The advisories also say that code importing pydantic.v1 from Pydantic v2 should be on 2.14.2 or later. Details are in what is Pydantic.
FastAPI and other users
FastAPI’s documentation sets out its own timeline: version 0.100.0 supported either Pydantic v1 or v2, 0.119.0 added partial support for pydantic.v1 inside v2, 0.126.0 dropped Pydantic v1, and 0.128.0 dropped pydantic.v1 as well. Current FastAPI declares pydantic>=2.9.0 as a requirement. Models migrate the same way as above; see FastAPI dependency injection explained and what is Pydantic. For the model-type trade-offs, see dataclasses vs Pydantic vs attrs, and the library itself is on its resource page.
Frequently Asked Questions
What changed between Pydantic v1 and v2?
Methods were renamed (dict became model_dump, parse_obj became model_validate), validators became field_validator and model_validator, the Config class became model_config, BaseSettings moved to the separate pydantic-settings package, Optional fields became required unless they have a default, and numbers are no longer coerced to strings. Pydantic’s core validation logic is now written in Rust.
How do I migrate from Pydantic v1 to v2?
Upgrade, then run the bump-pydantic tool, which the migration guide calls beta, to rewrite model config, validators and Optional defaults. It does not rename method calls such as .dict() and .json(), so fix those by hand, run your tests with warnings visible, and use pydantic.v1 for any code you cannot migrate yet.
What replaces .dict() and .json() in Pydantic v2?
model_dump() replaces .dict(), and model_dump_json() replaces .json(). The old names still work in v2 but emit a deprecation warning. .json() with arguments such as indent raises a TypeError, so call model_dump_json(indent=2) instead.
Why are my Optional fields now required in v2?
In v2, Optional[int] means the value may be None, but it no longer implies a default. A field with no default is required, and leaving it out raises ‘Field required’. Add = None to make it optional.
Does FastAPI still support Pydantic v1?
No. FastAPI 0.126.0 dropped Pydantic v1 and 0.128.0 dropped the pydantic.v1 compatibility layer, so current FastAPI releases require Pydantic v2. FastAPI’s own migration guide says the Pydantic team stopped supporting Pydantic v1 on Python 3.14 and above.