models.py
class Teacher(db.Model):
__tablename__ = 'teachers'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, unique=True)
schedules = db.relationship('Schedule', backref='teacher')
def __repr__(self):
return '<Teacher {}>'.format(self.name)
class Group(db.Model):
__tablename__ = 'groups'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, unique=True)
schedules = db.relationship('Schedule', backref='group')
def __repr__(self):
return '<Group {}>'.format(self.name)
class Schedule(db.Model):
__tablename__ = 'schedule'
id = db.Column(db.Integer, primary_key=True)
group_id = db.Column(db.Integer, db.ForeignKey('group.id'))
teacher_id = db.Column(db.Integer, db.ForeignKey('teacher.id'))
weekday = db.Column(db.Integer)
lesson_name = db.Column(db.String(100))
time_start = db.Column(db.String)
time_end = db.Column(db.String)
time = db.Column(db.Integer)
week = db.Column(db.Integer)
date = db.Column(db.String)
auditory_name = db.Column(db.String)
def __repr__(self):
return '<Schedule g:{} l:{} t:{} >'.format(self.group_id, self.lesson_name, self.teacher_id )
Ошибка:
sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'schedule.group_id' could not find table 'group' with which to generate a foreign key to target column 'id'
Подскажите в чем проблема?