SQLAlchemy: why use ForeignKey(..., ondelete="CASCADE") if relationship(..., cascade="all, delete-orphan") already exists?
Body I’m using SQLAlchemy 2.x with PostgreSQL and declarative models. I have a parent-child relationship between User and Testimonial. from __future__ import annotations from datetime import datetime from sqlalchemy import String, ForeignKey, DateTime, func, create_engine from sqlalchemy.orm import ( DeclarativeBase, Mapped, mapped_column, relationship, Session, ) class Base(DeclarativeBase): pass class User(Base): __tablename__ = "users" id: Mapped[str] = mapped_column(String, primary_key=True) testimonials: Mapped[list["Testimonial"]] = relationship( "Testimonial", back_populates="user", cas
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.