I have a problem with splitting tables with relationships in different files. I want the tables below to be in three separate files and import TableA to a third-party page, but I cannot control the loading order.
In most cases, I get the following error.
sqlalchemy.exc. InvalidRequestError: when initializing mapper Mapper | TableA | tablea, expression "TableB" could not find the name ("name" TableB "is not defined"). If it is a name class, consider adding this relationship () to the class after defining both dependent classes.
class TableA(Base): __tablename__ = "tablea" id = Column(Integer, primary_key=True) name = Column(String) tableB = relationship("TableB", secondary = TableC.__table__) class TableB(Base): __tablename__ = "tableb" id = Column(Integer, primary_key=True) name = Column(String) class TableC(Base): __tablename__ = "tableab" tableAId = Column("table_a_id", Integer, ForeignKey("TableA.id"), primary_key=True) tableBId = Column("table_b_id", Integer, ForeignKey("TableB.id"), primary_key=True)
python sqlalchemy relationship
bozhidarc
source share