class BusinessUnit(models.Model):
class Meta:
db_table = 'carecode_business_unit'
parent_business_unit = models.ForeignKey(BusinessUnit)
"BusinessUnit">
是否有可能在Django中创建一个自动引用模型?
class BusinessUnit(models.Model):
class Meta:
db_table = 'carecode_business_unit'
parent_business_unit = models.ForeignKey('self', on_delete=models.CASCADE, default=None)
class BusinessUnit(models.Model):
class Meta:
db_table = 'carecode_business_unit'
parent_business_unit = models.ForeignKey("BusinessUnit", on_delete=models.set_NULL)
在模型周围添加引号。你不能直接引用父类,但是django可以用引号惰性加载它。