使用 sqlalchemy 在 SQLite 中创建 JSON 类型的列

2021-12-30 00:00:00 python sqlalchemy json sqlite

是否可以使用 sqlalchemy 在 SQLite 中创建 JSON 类型的列?我试过了

Is it possible to create JSON type Column in SQLite with sqlalchemy? I've tried

import sqlalchemy.types as types
...
myColumn = Column(types.JSON())

from sqlalchemy import JSON
...
mycolumn = Column(JSON) 

两者都收到错误消息:

编译器无法渲染

想知道在 sqlalchemy 中是否有任何解决方案,或者我应该改为改为 SQL.提前致谢.

Wondering if there is any solution in sqlalchemy or I should just change into SQL instead. Thanks in advance.

[更新] SQLite 3.16.0 版

[Updates] SQLite version 3.16.0

推荐答案

JSON 直到 3.9 版才添加到 SQLite.您需要升级您的 SQLite 或将您的 json 转换为字符串并按原样保存,同时在将其拉出时将其转换回 json 对象.

JSON was not added to SQLite until version 3.9. You'll either need to upgrade your SQLite or convert your json to a string and save it as such, while converting it back to a json object when you pull it out.

相关文章