I have quite a complex project architecture which involves several applications whose models contains cross references.
For example, I have a billing.Premium
model - which belongs to the billing
app - that is referenced by another model whose name is payments.PaymentJob
through a one to one field:
('premium', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, to='billing.Premium', verbose_name='premium'))
(This code comes from one of payment
's migrations)
But I have come to some point when I need to rename billing.Premium
to billing.PremiumInstallment
and this is when the funny part comes: after having refactored my code to replace the model name, I try to django-admin makemigrations
, it leads to the following error:
ValueError: The field payments.PaymentJob.premium was declared with a lazy reference to 'billing.premium', but app 'billing' doesn't provide model 'premium'.
It appears like my migration has been broken since I have renamed the model of an external application. I do not know how to fix this in a fancy way, I mean generating some migration without error and that would be applied when I run django-admin migrate
.
Any idea?