1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #21961 -- Added support for database-level delete options for ForeignKey.

Thanks Simon Charette for pair programming.

Co-authored-by: Nick Stefan <NickStefan12@gmail.com>
Co-authored-by: Akash Kumar Sen <71623442+Akash-Kumar-Sen@users.noreply.github.com>
Co-authored-by: Simon Charette <charette.s@gmail.com>
This commit is contained in:
Mariusz Felisiak
2025-10-18 15:03:50 +02:00
committed by GitHub
parent b1e0262c9f
commit 0c487aa3a7
33 changed files with 838 additions and 67 deletions

View File

@@ -71,6 +71,21 @@ queries:
See :doc:`fetch modes </topics/db/fetch-modes>` for more details.
Database-level delete options for ``ForeignKey.on_delete``
----------------------------------------------------------
:attr:`.ForeignKey.on_delete` now supports database-level delete options:
* :attr:`~django.db.models.DB_CASCADE`
* :attr:`~django.db.models.DB_SET_NULL`
* :attr:`~django.db.models.DB_SET_DEFAULT`
These options handle deletion logic entirely within the database, using the SQL
``ON DELETE`` clause. They are thus more efficient than the existing
Python-level options, as Django does not need to load objects before deleting
them. As a consequence, the :attr:`~django.db.models.DB_CASCADE` option does
not trigger the ``pre_delete`` or ``post_delete`` signals.
Minor features
--------------