pydantic-sqlalchemy icon indicating copy to clipboard operation
pydantic-sqlalchemy copied to clipboard

Error with MySQL DateTime! str type expected (type=type_error.str)

Open AliMuhammadOfficial opened this issue 4 years ago • 1 comments

I have created my model from pre-existing MySQL database everything working fine butt when I add DateTime: str gives error. str type expected (type=type_error.str)

AliMuhammadOfficial avatar Jun 15 '21 12:06 AliMuhammadOfficial

from pydantic import BaseModel from datetime import datetime

class YourPydanticModel(BaseModel): datetime_column: datetime # Use appropriate datetime type here

Example usage

data = { "datetime_column": "2023-09-03T12:34:56" # Replace with your actual datetime string }

pydantic_instance = YourPydanticModel(**data) print(pydantic_instance)

ljluestc avatar Sep 03 '23 19:09 ljluestc