Skip to content

Commit

Permalink
add example of how to set up with init_app method (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
wgwz authored and miguelgrinberg committed Dec 6, 2019
1 parent f4f19f5 commit 6a76c24
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,23 @@ The following example initializes the extension with the standard Flask command-
from flask_migrate import Migrate
migrate = Migrate(app, db)

The two arguments to ``Migrate`` are the application instance and the Flask-SQLAlchemy database instance. The ``Migrate`` constructor also takes additional keyword arguments, which are passed to Alembic's ``EnvironmentContext.configure()`` method. As is standard for all Flask extensions, Flask-Migrate can be initialized using the ``init_app`` method as well.
The two arguments to ``Migrate`` are the application instance and the Flask-SQLAlchemy database instance. The ``Migrate`` constructor also takes additional keyword arguments, which are passed to Alembic's ``EnvironmentContext.configure()`` method. As is standard for all Flask extensions, Flask-Migrate can be initialized using the ``init_app`` method as well::

from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

db = SQLAlchemy()
migrate = Migrate()

def create_app():
"""Application-factory pattern"""
...
...
db.init_app(app)
migrate.init_app(app, db)
...
...
return app

When using Flask-Script's command-line interface, the extension is initialized as follows::

Expand Down

0 comments on commit 6a76c24

Please sign in to comment.