title: creating tables from different models with sqlalchemy
body: <p>I have different models e.g. model1.py, model2.py etc. Some how tables are being created following <a href="http://flask.pocoo.org/docs/patterns/sqlalchemy/" rel="nofollow noreferrer">pocoo link</a>, which required to be invoked from terminal.</p>
  <p>But</p>
  <pre><code>    def init_db():
          import model.model1
          import model.model2
          Base.metadata.create_all(bind=engine)
  </code></pre>
  <p>This is not working, rather requires to be invoked from terminal.</p>
  <pre><code>&gt;&gt; from database import init_db
  &gt;&gt; init_db() #works
  </code></pre>
  <p><img src="https://i.stack.imgur.com/4oO84.png" alt="enter image description here" /></p>
  <hr />
  <h1>database.py</h1>
  <pre><code>from sqlalchemy import create_engine
  from sqlalchemy.orm import scoped_session, sessionmaker
  from sqlalchemy.ext.declarative import declarative_base
  
  engine = create_engine('sqlite:///xyz.sqlite', echo=True)
  db_session = scoped_session(sessionmaker(autocommit=False,
                                      autoflush=False,
                                      bind=engine))
  Base = declarative_base()
  Base.query = db_session.query_property()
  
  def init_db():
     import model.admin # from model.admin import User doesnt help either
     import model.role
     Base.metadata.create_all(bind=engine)
  
  if __name__ == '__main__':
     init_db()
  </code></pre>
  <h1>admin.py</h1>
  <pre><code>from sqlalchemy import Column, Integer, String
  from database import Base
  
  class User(Base):
      __tablename__ = 'users'
      id = Column(Integer, primary_key=True)
      name = Column(String(50), unique=True)
      email = Column(String(120), unique=True)
  
      def __init__(self, name=None, email=None):
          self.name = name
          self.email = email
  
      def __repr__(self):
          return '&lt;User %r&gt;' % (self.name)
  </code></pre>
  <p>There are no errors although an empty db file is generated.
  How can database be created from multiple models?</p>