summaryrefslogtreecommitdiff
path: root/django/db/backends/base/operations.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2025-10-18 15:03:50 +0200
committerGitHub <noreply@github.com>2025-10-18 15:03:50 +0200
commit0c487aa3a7b2417481bf48c1e5355c855873e210 (patch)
tree33b92a3bdf11f66d0f67fe4b4338084c7028c709 /django/db/backends/base/operations.py
parentb1e0262c9f9d11eae6230b51c5aa5d71122d5f05 (diff)
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>
Diffstat (limited to 'django/db/backends/base/operations.py')
-rw-r--r--django/db/backends/base/operations.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py
index 9822a7fbb1..e345701438 100644
--- a/django/db/backends/base/operations.py
+++ b/django/db/backends/base/operations.py
@@ -254,6 +254,16 @@ class BaseDatabaseOperations:
if sql
)
+ def fk_on_delete_sql(self, operation):
+ """
+ Return the SQL to make an ON DELETE statement.
+ """
+ if operation in ["CASCADE", "SET NULL", "SET DEFAULT"]:
+ return f" ON DELETE {operation}"
+ if operation == "":
+ return ""
+ raise NotImplementedError(f"ON DELETE {operation} is not supported.")
+
def bulk_insert_sql(self, fields, placeholder_rows):
placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
values_sql = ", ".join([f"({sql})" for sql in placeholder_rows_sql])