class Client(models.Model):
client_id = models.CharField(primary_key=True, max_length=255)
name = models.CharField(max_length=255, blank=False)
class Cont(models.Model):
contid = models.CharField(max_length=255, primary_key=True)
Client = models.ForeignKey(Client, on_delete=models.PROTECT)
class ContractDailyIndent(models.Model):
id = models.CharField(max_length=255, primary_key=True)
cont = models.ForeignKey(Cont, on_delete=models.PROTECT)
class VDLContract(models.Model):
id = models.CharField(max_length=255, primary_key=True)
contractindent = models.ForeignKey(ContractDailyIndent,
on_delete=models.PROTECT)
此行出现错误 VDLContract.objects.filter(contractindent__cont__Client__in = clients).delete()
出现错误:
回溯(最近通话最近): 文件“ /home/puranjay/Documents/FeasOpt/new/fo_ftl_puranjay/mysite/empanelment/views.py”,行10432,在update_client_type中 delete_client_type(用户,client_type_id) 文件“ /home/puranjay/Documents/FeasOpt/new/fo_ftl_puranjay/mysite/empanelment/views.py”,行105,在delete_client_type中 delete_indent_models(用户,客户端) 文件“ /home/puranjay/Documents/FeasOpt/new/fo_ftl_puranjay/mysite/empanelment/utility.py”,行962,在delete_indent_models中 提高e 文件“ /home/puranjay/Documents/FeasOpt/new/fo_ftl_puranjay/mysite/empanelment/utility.py”,第941行,在delete_indent_models中 VDLContract.objects.filter(contractindent__cont__Client__in = clients).delete()
文件“ /home/puranjay/Documents/FeasOpt/env/venv/lib/python3.6/site-packages/django/db/models/query.py”,第661行,已删除 collector.collect(del_query)
第222行中的文件“ /home/puranjay/Documents/FeasOpt/env/venv/lib/python3.6/site-packages/django/db/models/deletion.py” field.remote_field.on_delete(self,field,sub_objs,self.using)
TypeError:“ NoneType”对象不可调用
答案 0 :(得分:1)
我尝试在本地计算机上实现您的问题。 Django由于外键约束而导致此错误。当您的外键依赖于其他模型时,会发生这种情况,在这种情况下,VDLContract可能依赖于其他模型,因此需要首先删除。