title: Flask-Migrate `db upgrade` fails with "relation does not exist"
body: <p>I'm working in a development environment on a flask-app with a Postgres 10 database that has ~80 tables. There are lots of relationships and ForeignKeyConstraints networking it all together. </p>
  
  <p>It was working fine with Flask-Migrate. I'd bootstrapped and migrated up to this point with ~80 tables. But, I wanted to test out some new scripts to seed the database tables, and thought it would be quickest to just drop the database and bring it back up again using Flask-Migrate. </p>
  
  <p>In this process, the migration folder was deleted, so I just started over fresh with a <code>db init</code>.  Then ran <code>db migrate</code>. I manually fixed a few imports in the migrate script.  Finally, I ran <code>db upgrade</code>. </p>
  
  <p>However, now with all these 80 <code>create_table</code> commands in my migrate script, when I run <code>db_upgrade</code>, I receive an error:</p>
  
  <pre><code>sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) relation "items" does not exist
  </code></pre>
  
  <p>I receive this error for every Child table that has a ForeignKeyConstraint if the Child table is not in an order which is below the Parent table in the migration file. </p>
  
  <p>But, the autogenerated script from <code>db migrate</code> has the tables sorted alphabetically, ordered by table name. </p>
  
  <p>Referring to documentation, I don't see this importance of sort order mentioned. </p>
  
  <p>Bottom line is, it seems I'm either forced to write a script to sort all these tables in an order where the Parent table is above the Child table. Or else, just cut and paste like a jigsaw puzzle until all the tables are in the required order.  </p>
  
  <p>What am I missing?  Is there an easier way to do this with Flask-Migrate or Alembic?</p>