python - sqlalchemy-sqlite 数据库当前(01/2018)是否与 JSON 对象直接兼容?
问题描述
我目前正在尝试创建一个包含 JSON 对象列的数据库:
import sqlalchemy as sql
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref
from sqlalchemy import create_engine
from sqlalchemy.types import JSON
# Creating the Base Object for the tables.
Base = declarative_base()
class Observations(Base):
# Declaring the tablename.
__tablename__='observations'
# Defining the PK column.
OBS_id=sql.Column(sql.Integer, primary_key=True)
# Defining a FK column to stabilishes the connection between this table
# and the ActiveRegion table.
ar_id=sql.Column(sql.Integer, sql.ForeignKey(ActiveRegion.AR_id))
# Creating a column to store the sharp metadata as a json object.
hmi_meta_data = sql.Column('hmimetadata', JSON, nullable=False)
但是,当我运行代码来构建数据库时,我得到一个CompileError
说:
CompileError: (in table 'observations', column 'hmimetadata'): Compiler <sqlalchemy.dialects.sqlite.base.SQLiteTypeCompiler object at 0x1c1e2b45f8> can't render element of type <class 'sqlalchemy.sql.sqltypes.JSON'>
我已经在 SO 上找到了一些解决方法来实现一个带有 JSON 对象的列,但是由于这个问题是不久前被问到的,我想知道是否有一个本机支持可以消除这种实现的需求。
根据 sqlalchemy types文档,JSON 类型应该适用于具有实际 JSON 类型的 SQL 后端,其中包括版本 3.9 的 SQLite。我正在检查我的 3.26 版本,它是最后一个版本(sqlite 发布网站)。那么这是未来 sqlalchemy 版本的里程碑吗?或者还有什么我没有考虑的吗?
谢谢。
解决方案
推荐阅读
- python - Python逐行请求文件中的数据
- android - 未使用 Google Drive Rest API V3 下载文件
- java - Java 基本并发通信器 - 不完全接受连接
- python - Python - 高性能视频流缓冲区
- android - android - 在活动和后台服务之间进行通信的最佳方式
- python - 使用python从文本中删除链接
- linux - 如何以百分比显示 CPU 使用率的准确计算
- python - 启动Django时枚举ValueError python3
- android - 尝试在 React Native 中从我的 Android 设备获取推送令牌时出现“无法获取设备的 GCM 令牌”,但出现此错误:
- angular - Angular Reactive Forms:在表单提交时将数据保存在模型中