我真的很累,我正在尝试建立关系,但做不到,有人可以帮助我吗?
__tablename__ = 'Period'
id = db.Column(db.Integer)
hour = db.Column(db.Integer, nullable=False, primary_key=True)
minute = db.Column(db.Integer, nullable=False, primary_key=True)
sound_id = db.Column(db.Integer, db.ForeignKey("Sound.id")), nullable=False)
sound = db.relationship("AudioModel", post_update=True)
_tablename_ = 'Sound'
id = db.Column(db.Integer, primary_key=True)
basename = db.Column(db.String(30), unique=True)
periods = db.relationship('PeriodModel', lazy='dynamic')
这给了我错误:
sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship AudioModel.periods - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
答案 0 :(得分:0)
使用__tablename__
代替_tablename_
,这应该可以解决。