python flask_migrate run - Flask - ImportError: No module named migrate.versioning

3 Answers

pip install sqlalchemy==0.7.9 


pip install sqlalchemy-migrate==0.7.2 


optionally this flask-whooshalchemy==0.55a should solve the problem

migration sqlalchemy migrations

I'm working through a flask tutorial and am trying to run a script that creates a database instead of doing it through the command line. It uses the SQLAlchemy-migrate package, but when I try to run the script, it gives an ImportError.

This is the terminal output:

Sean:app seanpatterson$ python ./ 
Traceback (most recent call last):
  File "./", line 2, in <module>
    from migrate.versioning import api
ImportError: No module named migrate.versioning

This is the script:

from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from app import db
import os.path
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
    api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')

This is the config file it references:

#!/usr/bin/env python
import os
basedir = os.path.abspath(os.path.dirname(__file__))

SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db')
SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository')

This application is being run with a virtual environment. This are the module that relates to it that I have installed in the environment:


Any help appreciated

flask/bin/pip install flask-sqlalchemy without defining the version worked fine for me.

I had the same problem - "No module named migrate.versioning", and everything is much easier than we are talking about, you need to perform the commands "run" file: or file: if you using PyCharm (not from the terminal). And you will have the expected output: "New migration saved as D:...there is my path...\microblog\db_repositort/versions/ Current database version: 1"