如何在 pewee BlobField 中存储二进制数据

How to store binary data in pewee BlobField

如何使用 peewee 在 SQLite 数据库中存储二进制数据 io.BytesIO()

当我尝试将它存储在 BloomField 中时,出现以下错误:

ValueError: Value must be either a bytes, memoryview or BigBitFieldData instance.

看来您实际上并没有使用 BlobField。但是,要将 BytesIO 对象中的数据存储到 actual BlobField,您可以:

# io.BytesIO.get_value() method should return bytes.
some_model.blob_field = bytesio_obj.getvalue()

基于作者的回答,我在这里为不熟悉此 io

的人提供更多 end-to-end 示例
with open("file.parquet.gzip", "rb") as f:
    bytesio_obj = io.BytesIO(f.read())
    binary = bytesio_obj.getvalue()

some_model.blob_field = binary

来源: