pythondatabaseflaskflask-sqlalchemyflask-migrate

flask db init using flask migrate


I was try to migrate my database using flask_migrate when i was hitting the flask db init that time getting below error.

 Error: While importing 'app', an ImportError was raised:
Traceback (most recent call last):
  File "C:\Users\Admin\Desktop\Flask REST APIs\.venv\lib\site-packages\flask\cli.py", line 245, in locate_app    __import__(module_name)
  File "C:\Users\Admin\Desktop\Flask REST APIs\app.py", line 6, in <module>
    from db import db
  File "C:\Users\Admin\Desktop\Flask REST APIs\db.py", line 1, in <module>
    from flask_sqlalchemy import SQLAlchemy
  File "C:\Users\Admin\Desktop\Flask REST APIs\.venv\lib\site-packages\flask_sqlalchemy\__init__.py", line 14, in <module>
    from flask import _app_ctx_stack, abort, current_app, request
ImportError: cannot import name '_app_ctx_stack' from 'flask' (C:\Users\Admin\Desktop\Flask REST APIs\.venv\lib\site-packages\flask\__init__.py)
Usage: flask [OPTIONS] COMMAND [ARGS]...
Try 'flask --help' for help.

Error: No such command 'db'.

I have try diffence version on flask to install and uninstall but it will geting same error or diffence some things on it.


Solution

  • You are using versions of Flask and Flask-SQLAlchemy that are incompatible with each other. You may want to make sure that Flask, Flask-SQLAlchemy, SQLAlchemy, Flask-Migrate and Alembic are upgraded to their latest versions to eliminate incompatibilities between them.