title: SQLAlchemy extension isn't registered when running app with Gunicorn
body: <p>I have an application that works in development, but when I try to run it with Gunicorn it gives an error that the "sqlalchemy extension was not registered".  From what I've read it seems that I need to call <code>app.app_context()</code> somewhere, but I'm not sure where.  How do I fix this error?</p>
  
  <pre><code># run in development, works
  python server.py
  
  # try to run with gunicorn, fails
  gunicorn --bind localhost:8000 server:app
  
  AssertionError: The sqlalchemy extension was not registered to the current application.  Please make sure to call init_app() first.
  </code></pre>
  
  <p><code>server.py</code>:</p>
  
  <pre><code>from flask.ext.security import Security
  from database import db
  from application import app
  from models import Studio, user_datastore
  
  security = Security(app, user_datastore)
  
  if __name__ == '__main__':
      # with app.app_context(): ??
      db.init_app(app)
      app.run()
  </code></pre>
  
  <p><code>application.py</code>:</p>
  
  <pre><code>from flask import Flask
  
  app = Flask(__name__)
  app.config.from_object('config.ProductionConfig')
  </code></pre>
  
  <p><code>database.py</code>:</p>
  
  <pre><code>from flask.ext.sqlalchemy import SQLAlchemy
  db = SQLAlchemy()
  </code></pre>