You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS7+Python3.8环境下superset db upgrade遇SQLAlchemy操作错误

解决Apache Superset 2.1.0在CentOS7执行superset db upgrade的SQLite语法错误问题

问题根源

CentOS7默认预装的SQLite版本为3.7.x,而Superset 2.1.0的数据库迁移脚本中使用了ALTER TABLE report_schedule RENAME extra TO extra_json这类重命名字段的语法——该语法是SQLite 3.25.0才引入的特性,旧版本SQLite无法识别,因此触发sqlalchemy.exc.OperationalError。

解决方案

方案一:升级SQLite到兼容版本

通过源码编译安装高版本SQLite,让Python虚拟环境使用新的SQLite库:

  1. 安装编译依赖
sudo yum install -y wget gcc make
  1. 下载并编译SQLite(以3.39.0为例,可选择更高稳定版本)
wget https://www.sqlite.org/2023/sqlite-autoconf-3390000.tar.gz
tar xzf sqlite-autoconf-3390000.tar.gz
cd sqlite-autoconf-3390000
./configure --prefix=/usr/local
make
sudo make install
  1. 配置系统优先加载新SQLite库
echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/sqlite.conf
sudo ldconfig
# 验证版本,需显示3.25+
sqlite3 --version
  1. 重建虚拟环境并重新安装Superset
deactivate
rm -rf venv
python3.8 -m venv venv
. venv/bin/activate
pip install --upgrade setuptools pip
pip install apache-superset
superset db upgrade

方案二:改用生产级数据库(推荐)

SQLite仅适合测试场景,Superset官方推荐使用PostgreSQL或MySQL作为生产数据库,以PostgreSQL为例:

  1. 安装并初始化PostgreSQL
sudo yum install -y postgresql-server postgresql-contrib
sudo postgresql-setup initdb
sudo systemctl start postgresql
sudo systemctl enable postgresql
  1. 创建Superset专用数据库和用户
sudo -u postgres psql
CREATE USER superset WITH PASSWORD 'your_secure_password';
CREATE DATABASE superset OWNER superset;
GRANT ALL PRIVILEGES ON DATABASE superset TO superset;
\q
  1. 调整PostgreSQL连接配置
sudo vi /var/lib/pgsql/data/pg_hba.conf
# 将本地连接的认证方式从`ident`改为`md5`,示例:
# local   all             all                                     md5
sudo systemctl restart postgresql
  1. 配置Superset连接PostgreSQL
. venv/bin/activate
# 安装PostgreSQL驱动
pip install psycopg2-binary
# 创建Superset配置文件
echo "SQLALCHEMY_DATABASE_URI = 'postgresql://superset:your_secure_password@localhost/superset'" > superset_config.py
export SUPERSET_CONFIG_PATH=$(pwd)/superset_config.py
# 执行数据库升级
superset db upgrade

注意事项

  • 生产环境禁止使用SQLite,其不支持并发写入、缺乏事务隔离等特性会导致Superset运行异常
  • 升级SQLite后,需确保Python虚拟环境重新编译依赖的SQLite绑定库,因此必须重建虚拟环境

内容的提问来源于stack exchange,提问作者Mahebub A Sayyed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 17:52:54