title: Flask-Migrate sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column
body: <p>I am using Flask-Migrate in my application, with the following models:</p>
  
  <p><strong>listpull/models.py</strong></p>
  
  <pre><code>from datetime import datetime
  
  from listpull import db
  
  
  class Job(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      list_type_id = db.Column(db.Integer, db.ForeignKey('listtype.id'),
                               nullable=False)
      list_type = db.relationship('ListType',
                                  backref=db.backref('jobs', lazy='dynamic'))
      record_count = db.Column(db.Integer, nullable=False)
      status = db.Column(db.Integer, nullable=False)
      sf_job_id = db.Column(db.Integer, nullable=False)
      created_at = db.Column(db.DateTime, nullable=False)
      compressed_csv = db.Column(db.LargeBinary)
  
      def __init__(self, list_type, created_at=None):
          self.list_type = list_type
          if created_at is None:
              created_at = datetime.utcnow()
          self.created_at = created_at
  
      def __repr__(self):
          return '&lt;Job {}&gt;'.format(self.id)
  
  
  class ListType(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(80), unique=True, nullable=False)
  
      def __init__(self, name):
          self.name = name
  
      def __repr__(self):
          return '&lt;ListType {}&gt;'.format(self.name)
  </code></pre>
  
  <p><strong>run.py</strong></p>
  
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf-8 -*-
  
  from listpull import app, manager
  manager.run()
  </code></pre>
  
  <p><strong>listpull/__init__.py</strong></p>
  
  <pre><code>from flask import Flask
  from flask.ext.sqlalchemy import SQLAlchemy
  from flask.ext.script import Manager
  from flask.ext.migrate import Migrate, MigrateCommand
  from mom.client import SQLClient
  from smartfocus.restclient import RESTClient
  
  
  app = Flask(__name__)
  app.config.from_object('config')
  
  db = SQLAlchemy(app)
  
  migrate = Migrate(app, db)
  
  manager = Manager(app)
  manager.add_command('db', MigrateCommand)
  
  ...
  
  import listpull.models
  import listpull.views
  </code></pre>
  
  <p>I initialized the database using <code>./run.py db init</code> and then I run <code>./run.py db migrate</code> and I get the following error:</p>
  
  <pre><code>sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'job.list_type_id' could not find table 'listtype' with which to generate a foreign key to target column 'id'
  </code></pre>
  
  <p>What am I doing wrong here?</p>