Newer constraint declarations and Foreign Keys

76 views
Skip to first unread message

dans...@gmail.com

unread,
Mar 7, 2022, 12:43:10 PM3/7/22
to Django developers (Contributions to Django itself)
Hi guys,

I remember that there is a new way to declare constraints in class Meta on a model, and that this is preferable for unique_together constraints.

I've long wanted a way with Django to have database foreign key constraints cascade in the database rather than via Django.   Is there now a way to do this?

Thanks!

Adam Johnson

unread,
Mar 7, 2022, 2:32:20 PM3/7/22
to Django developers (Contributions to Django itself)
No, there is not currently a way in Django to declare such constraints. You can always create them in a migration using the RawSQL operation, then rely on them in your code.

This blog post relates to custom relationships which would allow you to model them, I think: https://schinckel.net/2021/07/14/django-implied-relationship/


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/3e28c4b0-896d-49fa-b768-a30c3db96c23n%40googlegroups.com.

charettes

unread,
Mar 7, 2022, 3:53:30 PM3/7/22
to Django developers (Contributions to Django itself)
If you're interested in following the development of the database level foreign key constraints feature you should CC to #21961 [0]

The latest attempt at implementing them was recently closed due to inactivity [1]

Cheers,
Simon

st...@jigsawtech.co.uk

unread,
Mar 8, 2022, 12:20:42 PM3/8/22
to Django developers (Contributions to Django itself)
I'm part of the way working through a solution for this for MySQL. I just need to finish off the tests and documentation then it will be up on GitHub I just had to put it on hold but it fixes an issue in MySQL 5.7+ for Django that otherwise occurs if the database you are using is used by anything outside of Django that may need to perform deletes
Reply all
Reply to author
Forward
0 new messages