DB_CASCADE in Django 6.1 and ManyToManyField

I upgraded my project to Django 6.1 thought to give the new on_delete=DB_CASCADE feature a try.

I ran into an issue with a ManyToManyField – it does not have an on_delete argument. When deleting a model instance that has a M2M field, I get a foreign key violation error.

I’m wondering if there are plans to add DB_CASCADE functionality to the ManyToManyField as well.

Hey @cuu508, thanks for trying out 6.1!

Can you show me an example failing case? I tried to follow your description, and I have a working example here:

Somewhat unexpected for me: I still got python delete collection on the through model. I’m not certain if we’re okay with that, or if we’d prefer to fire the system check that is meant to prevent mixing python/db delete variants in the relationship tree. The db deletes do work for the through table if you define it explicitly (shown commented out in the fiddle).

Let me know what’s failing for you?

Hey Jacob, thanks for looking into it!

I do not have the through table explicitly defined, I guess that’s the problem.

Thanks for raising the issue: I’ve opened a ticket to improve the system check so that this feedback is provided right away.