title: Reflecting tables with Flask-SQLAlchemy raises RuntimeError: application not registered
body: <p>I have an SQLite database to manage user logins, along with an existing MySQL database.  I added the MySQL database to the Flask-SQLAlchemy <code>SQLALCHEMY_BINDS</code> config.  When I try to reflect the tables, I get the following error:</p>
  
  <pre><code>RuntimeError: application not registered on db instance and no application bound to current context
  </code></pre>
  
  <p>How do I correctly reflect the tables?</p>
  
  <p><code>__init__.py</code>:</p>
  
  <pre><code>from flask import Flask
  from flask.ext.sqlalchemy import SQLAlchemy
  from config import config
  
  db = SQLAlchemy()
  
  def create_app(config_name):
      app = Flask(__name__)
      app.config.from_object(config[config_name])
      config[config_name].init_app(app)
  
      db.init_app(app)
  
      from .main import main as main_blueprint
      app.register_blueprint(main_blueprint)
  
      return app
  </code></pre>
  
  <p><code>manage.py</code>:</p>
  
  <pre><code>from myapp import create_app
  from flask.ext.migrate import Migrate, MigrateCommand
  
  app = create_app(os.getenv('FLASK_CONFIG') or 'default')
  manager = Manager(app)
  migrate = Migrate(app, db)
  manager.add_command('db', MigrateCommand)
  
  if __name__ == '__main__':
      manager.run()
  </code></pre>
  
  <p><code>models.py</code>:</p>
  
  <pre><code>from . import db, login_manager
  
  db.Model.metadata.reflect(db.engine)
  
  class Calls(db.Model):
      __table__ = db.Model.metadata.tables['Calls2']
      __bind_key__ = 'calls'
  
      def __repr__(self):
          return self.test1
  </code></pre>
  
  
  
  <pre><code>Traceback (most recent call last):
    File "./manage.py", line 6, in &lt;module&gt;
      from app.models import User, Role, Permission
    File "/home/ilias/Desktop/client-reporting/app/models.py", line 9, in &lt;module&gt;
      db.Model.metadata.reflect(db.engine)
    File "/home/ilias/Desktop/client-reporting/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 780, in engine
      return self.get_engine(self.get_app())
    File "/home/ilias/Desktop/client-reporting/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 809, in get_app
      raise RuntimeError('application not registered on db '
  RuntimeError: application not registered on db instance and no application bound to current context
  </code></pre>