2

I found this Stack Overflow question explaining that Flask 0.10 does not have the flask command. How should I initialize the database for Flask-Migrate?

I discovered this issue when following the documentation for Flask-Migrate. After installing the package and adding the configuration, the init db would not run.

(env) $ flask init db
-bash: flask: command not found
Community
  • 1
  • 1
rosendin
  • 611
  • 1
  • 10
  • 18

1 Answers1

2

Upgrade to Flask 0.11, which provides the flask command.

If you can't upgrade, install and configure Flask-CLI, which backports the command to 0.10.

from flask_migrate import migrate

migrate = Migrate(app, db)
FLASK_APP=my_app.py flask db init

If you can't upgrade and don't want to install Flask-CLI, install and configure Flask-Script, which is a previous system for adding commands and is still supported by Flask-Migrate.

from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager

migrate = Migrate(app, db)

manager = Manager(app)
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()
python manage.py db init
davidism
  • 121,510
  • 29
  • 395
  • 339