mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Added a db_constraint option to ForeignKeys.
This controls whether or not a database level cosntraint is created. This is useful in a few specialized circumstances, but in general should not be used!
This commit is contained in:
@@ -1051,6 +1051,19 @@ define the details of how the relation works.
|
||||
The field on the related object that the relation is to. By default, Django
|
||||
uses the primary key of the related object.
|
||||
|
||||
.. attribute:: ForeignKey.db_constraint
|
||||
|
||||
Controls whether or not a constraint should be created in the database for
|
||||
this foreign key. The default is ``True``, and that's almost certainly what
|
||||
you want; setting this to ``False`` can be very bad for data integrity.
|
||||
That said, here are some scenarios where you might want to do this:
|
||||
|
||||
* You have legacy data that is not valid.
|
||||
* You're sharding your database.
|
||||
|
||||
If you use this, accessing a related object that doesn't exist will raise
|
||||
its ``DoesNotExist`` exception.
|
||||
|
||||
.. attribute:: ForeignKey.on_delete
|
||||
|
||||
When an object referenced by a :class:`ForeignKey` is deleted, Django by
|
||||
|
||||
Reference in New Issue
Block a user