пример картинки
Код: Выделить всё
class ChampionshipsTable(Base):
__tablename__ = "championships"
id: Mapped[int] = mapped_column(primary_key=True)
CId: Mapped[int] = mapped_column(Integer(), unique=True)
championship_name = mapped_column(String(50))
class TournamentsTable(Base):
__tablename__ = "tournaments"
id: Mapped[int] = mapped_column(primary_key=True)
CId: Mapped[int] = mapped_column(ForeignKey("championships.CId"))
TId: Mapped[int] = mapped_column(Integer(), unique=True)
tournament_name: Mapped[str] = mapped_column(String(50))
class MatchesTable(Base):
__tablename__ = "matches"
id: Mapped[int] = mapped_column(primary_key=True)
CId: Mapped[int] = mapped_column(ForeignKey("championships.CId"))
TId: Mapped[int] = mapped_column(ForeignKey("tournaments.TId"))
match_id: Mapped[int] = mapped_column(Integer(), unique=True)
Я пытаюсь строить таблицы, как в примере «многие ко многим» в sqlalchemy, вот так:
Код: Выделить всё
class ChampionshipsTable(Base):
__tablename__ = "championships"
id: Mapped[int] = mapped_column(primary_key=True)
CId: Mapped[int] = relationship("TournamentsTable", secondary="matches", back_populates="championships")
championship_name = mapped_column(String(50))
class TournamentsTable(Base):
__tablename__ = "tournaments"
id: Mapped[int] = mapped_column(primary_key=True)
CId: Mapped[int] = relationship("ChampionshipsTable", back_populates="tournaments")
TId: Mapped[int] = relationship("MatchesTable", backref="tournaments")
tournament_name: Mapped[str] = mapped_column(String(50))
class MatchesTable(Base):
__tablename__ = "matches"
id: Mapped[int] = mapped_column(primary_key=True)
CId: Mapped[int] = mapped_column(ForeignKey("championships.id"))
TId: Mapped[int] = mapped_column(ForeignKey("tournaments.id"))
match_id: Mapped[int] = mapped_column(Integer(), unique=True)
Код: Выделить всё
sqlalchemy.exc.InvalidRequestError: Mapper 'Mapper[TournamentsTable(tournaments)]' has no property 'championships'. If this property was indicated from other mappers or configure events, ensure registry.configure() has been called.
Подробнее здесь: https://stackoverflow.com/questions/788 ... ny-many-to