Creating a column to store binary data (Buffer, Byte Array or BLOB) #609
Unanswered
gsusrafael
asked this question in
Questions
Replies: 1 comment
-
This question is pretty old, but seems to (still) be the first result when looking on how to handle binary data or files with SQLModel, so I'll leave here my solution: from sqlmodel import SQLModel, Column, Field, LargeBinary
class Document(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
name: str
filename: str
data: bytes = Field(sa_column=Column(LargeBinary)) the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
Python 3.10.11
Additional Context
Traceback (most recent call last):
File "/home/jesus/Workspace/WebApp/portal-pass-backend/main.py", line 18, in
from api.endpoints import example, cliente, residencial
File "/home/jesus/Workspace/WebApp/portal-pass-backend/api/endpoints/residencial.py", line 14, in
from api.models.residencial import (
File "/home/jesus/Workspace/WebApp/portal-pass-backend/api/models/residencial.py", line 13, in
class ResidencialBase(SQLModel):
File "/home/jesus/.virtualenvs/portal-pass/lib/python3.10/site-packages/sqlmodel/main.py", line 272, in new
new_cls = super().new(cls, name, bases, dict_used, **config_kwargs)
File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.new
File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.init
File "pydantic/fields.py", line 557, in pydantic.fields.ModelField.prepare
File "pydantic/fields.py", line 831, in pydantic.fields.ModelField.populate_validators
File "pydantic/validators.py", line 765, in find_validators
RuntimeError: no validator found for <class 'collections.abc.ByteString'>, see
arbitrary_types_allowed
in ConfigBeta Was this translation helpful? Give feedback.
All reactions