问题描述
当我从sqlite迁移到postgres时,无法对新数据库进行任何写操作。 日志显示以下错误:
Unique key conflict id= 10,already exist in table ab_user
解决方法
两种可能的情况:
方案A:您是从头开始,并且想要使用Postgres而不是sqlite。
- 安装postgres
- 将postgres连接字符串添加到superset_config.py文件
- 运行
superset db upgrade
,这将在Postgres上创建所有表 - 运行
superset init
- 启动超集
场景B::您已经填充了sqliteDB,并希望将其迁移到Postgres。
- 安装postgres
- 将postgres连接字符串添加到superset_config.py文件
- 将所有表从sqlite复制到postgres,可以通过多种方法进行。我的首选方法是使用红宝石
- 复制数据后,运行
superset db upgrade
和superset init
- 完成此操作后,您将需要更新表
information_schema.sequences
上Postgres上的键序列,否则将遇到唯一的键冲突错误。 - 启动超集
在两种情况下,运行superset db upgrade
后,您都应该在下面看到消息,这意味着您已经正确配置了superset_config.py。
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
通过设置环境变量,确保超集正在查看配置文件:
export PYTHONPATH=/home/local_settings/:$PYTHONPATH
OR
export SUPERSET_CONFIG_PATH=/home/local_settings/