Skip to content

how to use JSON type in sqlmodel , Problem with openapi.json, File "pydantic\json.py", line 90, in pydantic.json.pydantic_encoder TypeError: Object of type 'Column' is not JSON serializable #696

Closed Answered by muslih-DIY
muslih-DIY asked this question in Questions
Discussion options

You must be logged in to vote

Iam posting this to avoid the same mistake by other
The issue was in another line of code, where i missed the Field

    created_on: datetime =Column(
        DateTime(timezone=True),
        server_default=func.now()
        )
    updated_on: datetime = Column(
        DateTime(timezone=True),
        server_default=func.now(),
        server_onupdate=func.now()
        )

corrected code is as follows

    created_on: datetime = Field(sa_column=Column(
        DateTime(timezone=True),
        server_default=func.now()
        ))
    updated_on: datetime = Field(sa_column=Column(
        DateTime(timezone=True),
        server_default=func.now(),
        server_onupdate=func.now()
        ))

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@muslih-DIY
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by muslih-DIY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
1 participant