This is an extension to this question: How to move a model between two Django apps (Django 1.7)
I want to move a model M from an app A to app B using Django migrations without losing data. The best voted answer to the question (not the accepted one, the one by ozan) suggested usage of migrations.SeparateDatabaseAndState and doing it in two steps:
- Migration to delete the model and rename (not delete) the db table.
- Migration to create the new model and use the existing table for it.
This looks like a very clever way to me, however in my case there is another model N that has a foreign key to M. Now, when I call makemigrations to make the migration file in step two, I get an error because at that stage model A.M does no more exist:
ValueError: Lookup failed for model referenced by field C.N.m: A.M
Is there a way to handle this?