How can I prevent HistoricalModel Creation When Inheriting from Abstract Model?
I have an abstract base model, CompanyAwareModel, which includes historical tracking using TenantHistoricalRecords:
class CompanyAwareModel(RequestChangeReasonModelMixin, TenantModel, TimeStampedModel, metaclass=CompanyAwareMeta):
tenant_id = 'company_id'
company = models.ForeignKey(Company, on_delete=models.CASCADE)
history = TenantHistoricalRecords(inherit=True)
class Meta:
abstract = True
To create a variant of this model without historical tracking, I defined another abstract model:
class NoHistoryCompanyAwareModel(CompanyAwareModel):
history = None
class Meta:
abstract = True
Then, I define a concrete model inheriting from NoHistoryCompanyAwareModel:
class Counter(NoHistoryCompanyAwareModel):
...
However, when I run makemigrations, Django still creates a HistoricalCounter model, even though I explicitly set history = None in NoHistoryCompanyAwareModel.
Interestingly, if I define NoHistoryCompanyAwareModel without inheriting from CompanyAwareModel, like this:
class NoHistoryCompanyAwareModel(RequestChangeReasonModelMixin, TenantModel, TimeStampedModel, metaclass=CompanyAwareMeta):
tenant_id = 'company_id'
company = models.ForeignKey(Company, on_delete=models.CASCADE)
history = None
class Meta:
abstract = True
Then makemigrations does not create a historical table for Counter.
Question
Why does inheriting from CompanyAwareModel still create a historical table, even when history = None is explicitly set? And how can I ensure that Counter does not have a HistoricalCounter model while still inheriting from CompanyAwareModel?
I expect that when I inherit the NoHistoryComapnyAwareModel from the CompanyAawreModel and set the history to None it won't create a historicalCounter for my model.