Flask-Migrate sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column
You are letting Flask-SQLAlchemy choose the names for your tables. If I remember correctly, for a class called ListType
the table name will be list_type
(or something similar), not the listtype
that you specified in your foreign key.
My recommendation is that you specify your own table names using __tablename__
, that way they are explicit in the code and not magically determined for you. For example:
class Job(db.Model):
__tablename__ = 'jobs'
id = db.Column(db.Integer, primary_key=True)
list_type_id = db.Column(db.Integer, db.ForeignKey('list_types.id'),
nullable=False)
# ...
class ListType(db.Model):
__tablename__ = 'list_types'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), unique=True, nullable=False)
# ...