问题描述
今天试着在python3.7.2上安装最新的superset(0.28.1),在初始化数据库的时候报如下错误:
代码语言:javascript复制$ superset db upgrade
...
Traceback (most recent call last):
File "/home/jhadmin/.pyenv/versions/myenv-3.7.2/bin/superset", line 15, in <module>
cli()
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/click/[core.py](core.py)", line 722, in __call__
return self.main(*args, **kwargs)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/flask/[cli.py](cli.py)", line 380, in main
return AppGroup.main(self, *args, **kwargs)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/click/[core.py](core.py)", line 697, in main
rv = self.invoke(ctx)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/click/[core.py](core.py)", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/click/[core.py](core.py)", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/click/[core.py](core.py)", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/click/[core.py](core.py)", line 535, in invoke
return callback(*args, **kwargs)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/click/[decorators.py](decorators.py)", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/flask/[cli.py](cli.py)", line 257, in decorator
return __ctx.invoke(f, *args, **kwargs)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/click/[core.py](core.py)", line 535, in invoke
return callback(*args, **kwargs)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/flask_migrate/[cli.py](cli.py)", line 134, in upgrade
_upgrade(directory, revision, sql, tag, x_arg)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/flask_migrate/__[init__.py](init__.py)", line 95, in wrapped
f(*args, **kwargs)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/flask_migrate/__[init__.py](init__.py)", line 280, in upgrade
command.upgrade(config, revision, sql=sql, tag=tag)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/alembic/[command.py](command.py)", line 276, in upgrade
script.run_env()
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/alembic/script/[base.py](base.py)", line 475, in run_env
util.load_python_file(self.dir, "[env.py](env.py)")
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/alembic/util/[pyfiles.py](pyfiles.py)", line 90, in load_python_file
module = load_module_py(module_id, path)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/alembic/util/[compat.py](compat.py)", line 156, in load_module_py
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/superset/migrations/[env.py](env.py)", line 100, in <module>
run_migrations_online()
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/superset/migrations/[env.py](env.py)", line 93, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/alembic/runtime/[environment.py](environment.py)", line 839, in run_migrations
self.get_context().run_migrations(**kw)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/alembic/runtime/[migration.py](migration.py)", line 361, in run_migrations
step.migration_fn(**kw)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/superset/migrations/versions/[4451805bbaa1_remove_double_percents.py](4451805bbaa1_remove_double_percents.py)", line 82, in upgrade
replace('%%', '%')
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/superset/migrations/versions/[4451805bbaa1_remove_double_percents.py](4451805bbaa1_remove_double_percents.py)", line 53, in replace
.join(Table)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/sqlalchemy/orm/[query.py](query.py)", line 2235, in join
from_joinpoint=from_joinpoint,
File "<string>", line 2, in _join
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/sqlalchemy/orm/[base.py](base.py)", line 220, in generate
fn(self, *args[1:], **kw)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/sqlalchemy/orm/[query.py](query.py)", line 2414, in _join
left, right, onclause, prop, create_aliases, outerjoin, full
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/sqlalchemy/orm/[query.py](query.py)", line 2437, in _join_left_to_right
) = self._join_determine_implicit_left_side(left, right, onclause)
File "/home/jhadmin/.pyenv/versions/3.7.2/envs/myenv-3.7.2/lib/python3.7/site-packages/sqlalchemy/orm/[query.py](query.py)", line 2568, in _join_determine_implicit_left_side
"Can't determine which FROM clause to join "
sqlalchemy.exc.InvalidRequestError: Can't determine which FROM clause to join from, there are multiple FROMS which can join to this entity. Try adding an explicit ON clause to help resolve the ambiguity.
问题原因
这是 SQLAlchemy 库版本太高导致的,需要安装低版本的 SQLAlchemy 库。
解决办法
代码语言:javascript复制# 查看当前 SQLAlchemy 版本
$ pip list | grep -i sqlalchemy
Flask-SQLAlchemy 2.3.2
SQLAlchemy 1.3.2
SQLAlchemy-Utils 0.33.11
# 安装低版本 SQLAlchemy
$ pip install SQLAlchemy==1.2.18
然后重新运行 “superset db upgrade” 命令初始化数据库。