关系错误

时间:2019-04-15 15:41:07

标签: python-3.x flask-sqlalchemy

我真的很累,我正在尝试建立关系,但做不到,有人可以帮助我吗?

__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.

1 个答案:

答案 0 :(得分:0)

使用__tablename__代替_tablename_,这应该可以解决。