title: flask migrate upgrade not working after drop table
body: <p>I am using SqlAlchemy and Flask-migrate for DB migration. I have successfully init the DB and upgrade once using the following:</p>
  
  <blockquote>
    <p>python manage.py db init <br>
    python manage.py db migrate  # creates the migration script,faefc6a6c7ae,  as below: <br></p>
  </blockquote>
  
  <pre><code>"""empty message
  
  Revision ID: faefc6a6c7ae
  Revises: None
  Create Date: 2016-10-25 22:09:25.615569
  
  """
  
  # revision identifiers, used by Alembic.
  revision = 'faefc6a6c7ae'
  down_revision = None
  
  from alembic import op
  import sqlalchemy as sa
  
  
  def upgrade():
      ### commands auto generated by Alembic - please adjust! ###
      op.create_table('users',
      sa.Column('id', sa.Integer(), nullable=False),
      sa.Column('name', sa.String(length=100), nullable=False),
      sa.Column('email', sa.String(length=100), nullable=False),
      sa.Column('password', sa.String(length=100), nullable=False),
      sa.PrimaryKeyConstraint('id')
      )
      op.create_table('posts',
      sa.Column('id', sa.Integer(), nullable=False),
      sa.Column('title', sa.String(length=50), nullable=False),
      sa.Column('description', sa.String(length=50), nullable=False),
      sa.Column('author_id', sa.Integer(), nullable=True),
      sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
      sa.PrimaryKeyConstraint('id')
      )
      ### end Alembic commands ###
  
  
  def downgrade():
      ### commands auto generated by Alembic - please adjust! ###
      op.drop_table('posts')
      op.drop_table('users')
      ### end Alembic commands ###
  </code></pre>
  
  <p>and then </p>
  
  <blockquote>
    <p>python manage.py db upgrade  # that actually does the migrations and creates the 'users' and the 'posts' tables in the db.</p>
  </blockquote>
  
  <p>Now I run my test.py which has the following lines of code (apart from others):</p>
  
  <pre><code>from flask_testing import TestCase
  class BaseTestCase(TestCase):
      def create_app(self):
          app.config.from_object('config.TestConfig')
          return app
  
      def setUp(self):
          db.create_all()
          db.session.add(BlogPost("Test post", "This is a test. Only a test."))
          db.session.add(User("admin", "ad@min.com", "admin"))
          db.session.commit()
  
      def tearDown(self):
          db.session.remove()
          db.drop_all()
  </code></pre>
  
  <p>Now the tearDown() drops all tables in the db after the test.py finishes running. </p>
  
  <p>After this, now when I run </p>
  
  <blockquote>
    <p>python manage.py db upgrade</p>
  </blockquote>
  
  <p>it gives me the following messages on the console:</p>
  
  <blockquote>
    <p>INFO  [alembic.runtime.migration] Context impl MySQLImpl.<br>
    INFO [alembic.runtime.migration] Will assume non-transactional DDL.</p>
  </blockquote>
  
  <p>but does not really create the respective tables at all. I have a workaround though. So if I do a :</p>
  
  <blockquote>
    <p>python manage.py db migrate # which creates a new migration script (not very different from the previous one) as below:</p>
  </blockquote>
  
  <pre><code>"""empty message
  
  Revision ID: 848398c80589
  Revises: faefc6a6c7ae
  Create Date: 2016-10-26 00:06:26.468354
  
  """
  
  # revision identifiers, used by Alembic.
  revision = '848398c80589'
  down_revision = 'faefc6a6c7ae'
  
  from alembic import op
  import sqlalchemy as sa
  
  
  def upgrade():
      ### commands auto generated by Alembic - please adjust! ###
      op.create_table('users',
      sa.Column('id', sa.Integer(), nullable=False),
      sa.Column('name', sa.String(length=100), nullable=False),
      sa.Column('email', sa.String(length=100), nullable=False),
      sa.Column('password', sa.String(length=100), nullable=False),
      sa.PrimaryKeyConstraint('id')
      )
      op.create_table('posts',
      sa.Column('id', sa.Integer(), nullable=False),
      sa.Column('title', sa.String(length=50), nullable=False),
      sa.Column('description', sa.String(length=50), nullable=False),
      sa.Column('author_id', sa.Integer(), nullable=True),
      sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
      sa.PrimaryKeyConstraint('id')
      )
      ### end Alembic commands ###
  
  
  def downgrade():
      ### commands auto generated by Alembic - please adjust! ###
      op.drop_table('posts')
      op.drop_table('users')
      ### end Alembic commands ###
  </code></pre>
  
  <p>and then if I do </p>
  
  <blockquote>
    <p>python manage.py db upgrade </p>
  </blockquote>
  
  <p>again, the tables are created. </p>
  
  <p>Now I would like to understand <strong>why were the tables not created when</strong></p>
  
  <blockquote>
    <p>python manage.py db upgrade</p>
  </blockquote>
  
  <p><strong>was run the first time itself ?</strong>
  The 2 migration scripts created by db migrate are not really much different or are they? So, why won't the upgrade work the first time itself (when the upgrade actually has code that creates the tables) and why would it work perfectly when the new script is generated again (where the upgrade method itself has not changed at all as compared to the previous migrate script ?</p>