-
First Check
Commit to Help
Example Codefrom typing import Optional
from sqlmodel import Field, SQLModel, Column, JSON
class EmployeeMasterBase(SQLModel):
additional_info: Optional[dict] = Field(sa_column=Column(JSON)) Descriptioni was creating a Sqlmodel to conncect with postgres. \site-packages\fastapi\_compat.py", line 370, in get_model_definitions
m_schema, m_definitions, m_nested_models = model_process_schema(
File "pydantic\schema.py", line 582, in pydantic.schema.model_process_schema
File "pydantic\schema.py", line 623, in pydantic.schema.model_type_schema
File "pydantic\schema.py", line 249, in pydantic.schema.field_schema
File "pydantic\schema.py", line 217, in pydantic.schema.get_field_info_schema
File "pydantic\schema.py", line 996, in pydantic.schema.encode_default
File "pydantic\json.py", line 90, in pydantic.json.pydantic_encoder
TypeError: Object of type 'Column' is not JSON serializable
### Operating System
Windows
### Operating System Details
Windows 10, 64 bit
### SQLModel Version
sqlmodel = "^0.0.8"
### Python Version
Python 3.10.7
### Additional Context
_No response_ |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
How we approach when using json type in sqlmodel |
Beta Was this translation helpful? Give feedback.
-
iam closing it , i have to check on it again. |
Beta Was this translation helpful? Give feedback.
-
Iam posting this to avoid the same mistake by other 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()
)) |
Beta Was this translation helpful? Give feedback.
Iam posting this to avoid the same mistake by other
The issue was in another line of code, where i missed the Field
corrected code is as follows