title: It is necessary use db.init_app or SQLAlchemy(app) is the same in Flask?
body: <p>Checking Flask and Flask-SQLAlchemy doc i have a confusion, if i have:</p>
  
  <p><strong>models.py</strong>:</p>
  
  <pre><code>from flask_sqlalchemy import SQLAlchemy
  #:Use or not
  db = SQLAlchemy()
  
  class User(db.Model):
   __tablename__ = "USERS"
      id = db.Column(db.Integer, primary_key=True)
      username = db.Column(db.String(25), nullable=False)
      password = db.Column(db.String(255), nullable=False)
  </code></pre>
  
  <p><strong>config.py</strong>:</p>
  
  <pre><code>import os
  
  class Config(object):
      DEBUG = True
      SECRET_KEY = os.urandom(12)
      SQLALCHEMY_TRACK_MODIFICATIONS = False
      SQLALCHEMY_DATABASE_URI = "mysql://root:@localhost/example"
  </code></pre>
  
  <p><strong>app.py</strong>:</p>
  
  <pre><code>from config import Config
  from models import db
  from models import User
  
  app = Flask(__name__)
  app.config.from_object(Config)
  
  db = SQLAlchemy(app)
  
  if __name__ == "__main__":
      db.init_app(app)
      with app.app_context():
          db.create_all()
      app.run()
  </code></pre>
  
  <p><strong>is necessary use:</strong></p>
  
  <p><code>db = SQLAlchemy(app)</code> after <code>app.config.from_object(Config)</code>
  or <code>db.init_app(app)</code> is the same?</p>
  
  <p>Because i founded some examples of flask with only <code>db = SQLAlchemy()</code> in <code>models.py</code> and have <code>db.init_app(app)</code> before <code>app.run()</code></p>
  
  <p>And so founded examples with <code>db = SQLAlchemy(app)</code> override in <code>app.py</code> with no db.init_app(app)</p>
  
  <p>I printed both values and get:</p>
  
  <pre><code>with only db in models:
  
  &lt;SQLAlchemy engine=None&gt;
  the problem is:
  The app create the tables in my database
  But engine=None
  
  with db = SQLAlchemy(app) override
  
  &lt;SQLAlchemy engine=mysql://root:***@localhost/hsl_db?charset=utf8&gt;
  
  the problem is:
  The app dont create the tables in my database
  </code></pre>
  
  <p><em>What is the correct way to assign the database of SQLAlchemy to Flask app?</em></p>