我正在处理一个包含模型Family
的Django项目,该项目继承自BaseFamily
,类似于
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import pre_save
from .timestamped_model import TimeStampedModel
class BaseFamily(TimeStampedModel):
package = models.ForeignKey('lucy_web.Package',
models.SET_NULL,
blank=True,
null=True)
lucy_guide = models.ForeignKey(
User,
blank=True,
null=True,
related_name='lucy_guide_%(class)s',
limit_choices_to={'is_staff': True})
@receiver(pre_save)
def link_lucy_guide(sender, instance, **kwargs):
"""Assign company LucyGuide to family if not explicitly assigned."""
if not issubclass(sender, BaseFamily):
return
if instance.company and not instance.lucy_guide:
instance.lucy_guide = instance.company.lucy_guide
我们正在使用Django版本1.11.9;据我了解,如果未指定on_delete
,则默认为models.CASCADE
(参见the documentation)。
然而,在我目前的数据库中,我有一个家庭的实例(employee_first_name='Mark'
和employee_last_name='Flores'
)lucy_guide_id
687
:
但没有相应的auth_user
:
我的问题是:数据库是如何在这种状态下结束的?如果级联删除处于活动状态,family
是否应与其lucy_guide
一起删除?