[edit] solution found, details below
There are some interesting suggestions in a similar question but it doesn't help with my problem. Also, I have this app in production in several countries.
We are migrating an app and started with managed=False
on all models. We then had a claim_batch
app that has a migration 0002_capitationpayment
:
dependencies = [
('product', '__first__'),
('claim_batch', '0001_initial'),
]
# Some models with foreign keys to "product.Product"
The product
module doesn't have migrations but it has models. When I do a showmigrations
in this situation, I have:
product
(no migrations)
And it works fine somehow.
The problem is that I now need to add migration with a managed table in product
. When I do the makemigrations
and try to migrate
, I'm getting:
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration claim_batch.0002_capitationpayment is applied before its dependency product.0001_initial on database 'default'.
It makes sense. The claim_batch.0002 is referencing a migration that is now existing but was not applied and it should not be possible to apply it after its dependency. Except in this scenario.
If I try to remove the dependency from the already applied migration, I'm getting:
ValueError: The field claim_batch.CapitationPayment.product was declared with a lazy reference to 'product.product', but app 'product' isn't installed.
I'm guessing that a clean install with this would work fine but I have production systems in various countries running in this state. Starting from scratch is not really an option.
[EDIT]
I can get it to work by manually adding the initial migration of the product app into the django_migrations
table. It's not the best solution but it's manageable.