[Python] Sqlalchemy CASCADE delete mode is not applied [duplicate]

Discussão em 'Python' iniciado por Stack, Agosto 8, 2025.

  1. Stack

    Stack Membro Participativo

    I have a sqlalchemy table, the table created fine, but I don't see CASCADE delete mode in solution column. I am checking like this ( confdeltype is 'a' not 'c'):

    dbname=# select connamespace, conname, c.relname as child_table, p.relname as parent_table, confdeltype from pg_constraint join pg_class c on c.oid=conrelid join pg_class p on p.oid=confrelid;
    connamespace | conname | child_table | parent_table | confdeltype
    --------------+--------------------------+-------------+--------------+-------------
    2200 | tasks_files_task_id_fkey | tasks_files | tasks | a
    2200 | solutions_task_id_fkey | solutions | tasks | a
    (2 rows)


    Table:

    class Task(Base):
    __tablename__ = 'tasks'

    id = Column(String, unique=True, nullable=False, primary_key=True)
    ...
    files: Mapped[List["TaskFile"]] = relationship(cascade="all, delete")
    solution: Mapped[List["Solution"]] = relationship(cascade="all, delete")
    output_topic = Column(String)


    The table looks like this in psql:

    dbname=# \d+ tasks
    Table "public.tasks"
    Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
    --------------------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
    id | character varying | | not null | | extended | |
    external_id | character varying | | not null | | extended | |
    rq_id | character varying | | not null | | extended | |
    ...
    Indexes:
    "tasks_pkey" PRIMARY KEY, btree (id)
    Referenced by:
    TABLE "solutions" CONSTRAINT "solutions_task_id_fkey" FOREIGN KEY (task_id) REFERENCES tasks(id)
    TABLE "tasks_files" CONSTRAINT "tasks_files_task_id_fkey" FOREIGN KEY (task_id) REFERENCES tasks(id)
    Access method: heap

    Continue reading...

Compartilhe esta Página