Fix child delete failing due to SQLAlchemy nullifying FK before DB cascade
Add passive_deletes=True to daily_sessions and activity_logs relationships so the ORM defers to MySQL's ON DELETE CASCADE instead of trying to SET NULL. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,8 +16,8 @@ class Child(TimestampMixin, Base):
|
||||
|
||||
user: Mapped["User"] = relationship("User", back_populates="children") # noqa: F821
|
||||
daily_sessions: Mapped[list["DailySession"]] = relationship( # noqa: F821
|
||||
"DailySession", back_populates="child"
|
||||
"DailySession", back_populates="child", passive_deletes=True
|
||||
)
|
||||
activity_logs: Mapped[list["ActivityLog"]] = relationship( # noqa: F821
|
||||
"ActivityLog", back_populates="child"
|
||||
"ActivityLog", back_populates="child", passive_deletes=True
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user