title: How to do first migration in flask?
body: <p>I am working on an new project which is already developed in Flask and I have no knowledge of Flask. My company gave the project to me because I have Django experience.</p>
  
  <p>This is the structure of the project:</p>
  
  <pre><code>models
    -db.py
    -model1.py
    -model2.py
    - ..
  static
    - ..
  templates
    - ..
  myapp.py
  </code></pre>
  
  <p><code>myapp.py</code> contains all config files and server init code with all other functionality such as that for home page and sign up page.</p>
  
  <p>When I run <code>myapp.py</code> it runs OK, but the tables are not created automatically (I found that first migration has to be done). I have no idea how to do it.</p>
  
  <p>The project makes use of postgresql and SQLAlchemy form flask_sqlalchemy Modules.</p>
  
  <p><code>db.py</code> file: </p>
  
  <pre><code>from flask_sqlalchemy import SQLAlchemy
  
  db = SQLAlchemy()
  </code></pre>
  
  <p>All models have <code>from db import db</code></p>
  
  <p><code>myapp</code> file:</p>
  
  <pre><code># ===================================================================
  # SQL ALCHEMY
  # ===================================================================
  
  if (SERVER_MODE == RUN_MODE.PRODUCTION):
      app.config['SQLALCHEMY_DATABASE_URI'] = (
          os.environ["DATABASE_URL"]
      )
      app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  else:
      app.config['SQLALCHEMY_DATABASE_URI'] = (
          'postgresql://' +
          'creathiveswebapp:creathives' +
          '@' +
          'localhost/cl_creathives_pgdb'
      )
      app.config['SQLALCHEMY_ECHO'] = False
      app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
  
  db.init_app(app)
  </code></pre>
  
  <p>and </p>
  
  <pre><code>...
  # ===================================================================
  # START SERVER
  # ===================================================================
  
  if __name__ == "__main__":
      port = int(os.environ.get('PORT', 5000))
      if (SERVER_MODE == RUN_MODE.PRODUCTION):
          # TODO: Turn off debug
          app.run(host='0.0.0.0', port=port, debug=True)
      else:
          app.run(host='0.0.0.0')
  </code></pre>
  
  <p>How do I make first migration to create the tables.</p>