保留数据库内容更新字段但遇到flask db migrate -m ImportError: No module namedflask_babel

问题描述 投票:0回答:2

我正在保留数据库内容更新字段

  1. sudo systemctl 重启mysql

  2. pipenv 外壳

  3. flask 数据库历史记录

  4. mysql -u root -p erack

  5. 从alembic_version中选择*;

  6. 退出

  7. flask db migrate -m“您的消息”

但面临: flask db migrate -m ImportError:没有名为flask_babel的模块

mcsadmin@mcsadmin-VirtualBox:~/UI_Mgmt$ flask db migrate -m "YOUR MESSAGE"
 * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
Usage: flask db migrate [OPTIONS]

Error: While importing "app", an ImportError was raised:

Traceback (most recent call last):
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/flask/cli.py", line 240, in locate_app
    __import__(module_name)
  File "/home/mcsadmin/UI_Mgmt/app/__init__.py", line 7, in <module>
    from flask_babel import Babel
ImportError: No module named flask_babel

mcsadmin@mcsadmin-VirtualBox:~/UI_Mgmt$ pip install python-dotenv
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Collecting python-dotenv
  Downloading python_dotenv-0.18.0-py2.py3-none-any.whl (18 kB)
Requirement already satisfied: typing; python_version < "3.5" in /home/mcsadmin/.local/lib/python2.7/site-packages (from python-dotenv) (3.10.0.0)
Installing collected packages: python-dotenv
Successfully installed python-dotenv-0.18.0
mcsadmin@mcsadmin-VirtualBox:~/UI_Mgmt$ flask db migrate -m "YOUR MESSAGE"
Traceback (most recent call last):
  File "/home/mcsadmin/.local/bin/flask", line 8, in <module>
    sys.exit(main())
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/flask/cli.py", line 967, in main
    cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/flask/cli.py", line 425, in decorator
    with __ctx.ensure_object(ScriptInfo).load_app().app_context():
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/flask/cli.py", line 388, in load_app
    app = locate_app(self, import_name, name)
  File "/home/mcsadmin/.local/lib/python2.7/site-packages/flask/cli.py", line 240, in locate_app
    __import__(module_name)
  File "/home/mcsadmin/UI_Mgmt/agv.py", line 1, in <module>
    from upgradation import check_UI_Mgmt_version
  File "/home/mcsadmin/UI_Mgmt/upgradation.py", line 8
    def check_version_needed_update(current_version: str, update_version: str):
                                                   ^
SyntaxError: invalid syntax

我按照控制台建议

pip install python-dotenv
但仍然面临错误,我该如何处理这个问题

python linux database migration database-migration
2个回答
1
投票

您正在使用 Python 2 解释器。请尝试切换到Python 3并确保在Python 3环境中安装所有必需的库。


0
投票

我的

pipenv shell
输入了,但不起作用,所以当时我还没有进入虚拟版本

重新输入

pipenv shell
,然后
flask db migrate -m "YOUR any  MESSAGE"
就可以了

© www.soinside.com 2019 - 2024. All rights reserved.