title: How to use Flask-Migrate to do database migration?
body: <p>I come across a problem when playing with Flask-Migrate to upgrade/downgrade the database. There were two tables, <code>User</code> and <code>Post</code>, defined by the following classes:</p>
  
  <pre><code>class User(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      username = db.Column(db.String(64), index=True, unique=True)
      email = db.Column(db.String(120), index=True, unique=True)
      password_hash = db.Column(db.String(128))
      posts = db.relationship('Post', backref='author', lazy='dynamic')
  
      def __repr__(self):
          return '&lt;User {}&gt;'.format(self.username)
  
  class Post(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      body = db.Column(db.String(140))
      timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
      user_id = db.Column(db.Integer, db.ForeignKey('user.id')) 
  </code></pre>
  
  <p>And I have added some entries into these tables.</p>
  
  <p>Now the problem. :)</p>
  
  <p>For fun, I added a column to <code>User</code> table through: <code>dummy = db.Column(db.String(20))</code>. After modified the table schema, I ran the following commands: </p>
  
  <ol>
  <li><code>flask db migrate</code> ---- success</li>
  <li><code>flask db upgrade</code> ---- success</li>
  </ol>
  
  <p>Then I wanted to go back:</p>
  
  <ol start="3">
  <li>To restore the database back to previous state, I ran <code>flask db downgrade</code> ---- failed with the Error: <code>sqlite3.OperationalError: near "DROP": syntax error</code></li>
  <li>I tried to fix the error by deleting the <code>dummy = db.Column(db.String(20))</code> statement from <code>User</code> class, then ran <code>flask db downgrade</code> again ---- failed again with the same error.</li>
  <li>Then I think maybe the Flask-Migrate need to be aware of the deletion , so I ran <code>flask db migrate</code> ---- success</li>
  <li>Try <code>flask db upgrade</code> ---- failed again with the same error.</li>
  </ol>
  
  <p>So How does the flask-migrate work? And specifically, how can I restore the database to initial state (without the <code>dummy</code> attribute)?</p>
  
  <p>Thanks!</p>