使用 sqlalchemy 在 SQLite 中创建 JSON 类型的列 [英] Creating JSON type Column in SQLite with sqlalchemy

查看:43
本文介绍了使用 sqlalchemy 在 SQLite 中创建 JSON 类型的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 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.

这篇关于使用 sqlalchemy 在 SQLite 中创建 JSON 类型的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆