Код: Выделить всё
class TableA(Base):
__tablename__ = "tablea"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
tableb_ref: Mapped[List["TableB"]] = relationship(back_populates="tablea_ref", secondary="tablec")
Код: Выделить всё
class TableB(Base):
__tablename__ = 'tableb'
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(50), nullable=False)
tablea_ref: Mapped[List["TableA"]] = relationship(back_populates="tableb_ref", secondary="tablec")
Код: Выделить всё
class TableC(Base):
__tablename__ = "tablec"
tablea_id: Mapped[int] = mapped_column(ForeignKey('tablea.id', ondelete='CASCADE'), primary_key=True)
tableb_id: Mapped[int] = mapped_column(ForeignKey('tableb.id', ondelete='CASCADE'), primary_key=True)
Код: Выделить всё
sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper[CategoryOrm(categories)], expression 'product_categories' failed to locate a name ("name 'product_categories' is not defined"). If this is a class name, consider adding this relationship() to the class after both dependent classes have been defined.
Кто-нибудь знает, как это исправить?
Подробнее здесь: https://stackoverflow.com/questions/798 ... rent-files
Мобильная версия