Код: Выделить всё
from __future__ import annotations
class Parent(Base):
...
children: Mapped[list[Child]] = relationship("Child", back_populates="parent")
class Child(Base):
...
parent_id: Mapped[Optional[str]] = mapped_column(String, ForeignKey("parent.id", name="parent_id_fk", ondelete="CASCADE"), nullable=True, default=None)
parent: Mapped[Parent] = relationship("Parent", back_populates="children")
Подробнее здесь: https://stackoverflow.com/questions/781 ... ith-type-a