Skip to content
Advertisement

Validation error while inputting a record into Postgres

I have created a table using the following query,

JavaScript

Following is my models.py

JavaScript

Following is my schema.py

JavaScript

I use the following code to create an user,

JavaScript

The problem is that I’m getting the following error,

raise ValidationError(errors, field.type_) pydantic.error_wrappers.ValidationError: 1 validation error for AccountsInfo response -> created_on str type expected (type=type_error.str)

what am I missing?

Advertisement

Answer

raise ValidationError(errors, field.type_) pydantic.error_wrappers.ValidationError: 1 validation error for AccountsInfo response -> created_on str type expected (type=type_error.str)

In your table the created_on is DateTime.

JavaScript

But you declared as str in your Pydantic model.

JavaScript

Declare your field as datetime in Pydantic model. Also SQLAlchemy gives you ability to create datetime automatically.

JavaScript
Advertisement