﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21961	Add support for database-level cascading options	Christophe Pettus	Mariusz Felisiak	"Per a discussion on -developers, this ticket is to document this proposed new feature.

The general idea is to allow developers to specify that the database itself, rather than Django, should implement foreign key constraints where possible. The database can be considerably more efficient, and often can avoid locking situations, in a way that the Django backend can't.

The proposal is to add a models.CASCADE_DB, models.SET_NULL_DB, models.PROTECT_DB constants. These specify that the appropriate functionality is to be implemented in the database if the database supports it; otherwise, they are implemented in the Django core as now.

Some potential design issues with proposed solutions:

1. It is not an error to specify the _DB version with a database that doesn't support it. Instead, you get the non-_DB version.
2. The _DB version does not fire signals; this will need to be documented.
3. If a model A references a model B using CASCADE_DB, but model B references model C using regular CASCADE, a deletion of A won't cascade all the way to C. This needs to be documented. Another possibility is to make this an error condition and have model validation fail, but that seems excessive.
4. The _DB version is disallowed on generic foreign keys, because that way madness lies.
5. The implicit foreign key created from child to parent in model inheritance is never the _DB version. This is a shame, but there are two issues:
    a) Since it's created implicitly, there's no place to put it.
    b) Even if we extended the mechanism to allow manual specification of the key, deleting the parent wouldn't automatically delete the child."	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed		emorley@… andre@… Nick Stefan Hannes Ljungberg Carlton Gibson Florian Demmer Peter Thomassen Adrien Delessert Adam Johnson raydeal John Speno eduards-amped David Wobrock bcail lo0 Roman Donchenko Ryan Hiebert Mariusz Felisiak Tilman Koschnick Petr Přikryl loentwin	Ready for checkin	1	0	0	0	0	0
