What are the options for overriding Django's cascading delete behaviour?

后端 未结 3 1340
渐次进展
渐次进展 2020-12-13 01:41

Django models generally handle the ON DELETE CASCADE behaviour quite adequately (in a way that works on databases that don\'t support it natively.)

However, I\'m str

3条回答
  •  不思量自难忘°
    2020-12-13 02:16

    Just a note for those who run into this issue as well, there is now an built-in solution in Django 1.3.

    See the details in the documentation django.db.models.ForeignKey.on_delete Thanks for editor of Fragments of Code site to point it out.

    The simplest possible scenario just add in your model FK field definition:

    on_delete=models.SET_NULL
    

提交回复
热议问题