class Team(db.Model):
__tablename__ = "Teams"
id = db.Column(db.Integer, primary_key=True)
flashscore_id = db.Column(db.String(255), nullable=False, unique=True)
name = db.Column(db.String(255), nullable=False)
leagues = db.relationship("League",
secondary=league_teams_table)
standings = db.relationship('Standing', backref='teams', cascade="all,delete")
fixtures = db.relationship('Fixture', backref='teams', cascade="all,delete")
related_fixtures_table = db.Table('RelatedFixtures',
db.Column('fixture_id', db.Integer, db.ForeignKey('Fixtures.id')),
db.Column('related_fixture_id', db.Integer, db.ForeignKey('Fixtures.id')))
class Fixture(db.Model):
__tablename__ = "Fixtures"
id = db.Column(db.Integer, primary_key=True)
home_id = db.Column(db.Integer, db.ForeignKey('Teams.id'),
nullable=False)
away_id = db.Column(db.Integer, db.ForeignKey('Teams.id'),
nullable=False)
home_ref = db.relationship("Teams", backref="fixture", uselist=False, foreign_keys=[home_id])
away_ref = db.relationship("Teams", backref="fixture", uselist=False, foreign_keys=[away_id])
flashscore_id = db.Column(db.String(255), nullable=False, unique=True)
total_goals = db.Column(db.Integer, nullable=False)
total_fh_goals = db.Column(db.Integer, nullable=False, default=0)
total_sh_goals = db.Column(db.Integer, nullable=False, default=0)
total_home_goals = db.Column(db.Integer, nullable=False)
total_away_goals = db.Column(db.Integer, nullable=False)
total_home_fh_goals = db.Column(db.Integer, nullable=False, default=0)
total_home_sh_goals = db.Column(db.Integer, nullable=False, default=0)
total_away_fh_goals = db.Column(db.Integer, nullable=False, default=0)
total_away_sh_goals = db.Column(db.Integer, nullable=False, default=0)
related_fixtures = db.relationship("Fixture",
secondary=related_fixtures_table)
Я написал приведенный выше код, пытаясь определить множественные отношения между Fixture и Team. Когда я запускаю приложение и выполняю действие, я получаю следующую ошибку:
sqlalchemy.exc.AmbiguousForeignKeysError: Could not determine join condition between parent/child tables on relationship Team.fixtures - there are multiple foreign key paths linking the tables. Specify the 'foreign_keys' argument, providing a list of those columns which should be counted as containing a foreign key reference to the parent table.
Я попытался решить эту проблему, добавив следующие две строки:
home_ref = db.relationship("Teams", backref="fixture", uselist=False, foreign_keys=[home_id])
away_ref = db.relationship("Teams", backref="fixture", uselist=False, foreign_keys=[away_id])
Но я все еще получаю ту же ошибку. Кто-нибудь может мне помочь?