Skip to content Skip to sidebar Skip to footer

Why Is The "on_update" Option Not Present In Django Relationship Fields?

I'm using Django 3.0 + MariaDB. I've created a models.py from an existent database with the 'python manage.py inspectdb > models.py' command. I need now to set the options for t

Solution 1:

Django does not actually use database cascade options even for on_delete

on_delete doesn’t create an SQL constraint in the database. Support for database-level cascade options may be implemented later.

There are convenient advantages of the following as your app can react to pre_delete and post_delete signals, but there is also slight disadvantage in terms of performance


Regarding ON_UPDATE

It was not implemented and it was fairly rarely used as normally you would never change your model id's

You still can create SQL migration if you need something specific on database level or emulate it on application level for better control (for instance overriding model save method)


Regarding additional database constraints not related to foreign key, there are docs related to them here and specific to postgreSQL here

Post a Comment for "Why Is The "on_update" Option Not Present In Django Relationship Fields?"