I have two Django apps. A
, the core app, and B
, which started out as an individual app, but actually fits better within A
as we later discovered. I'm able to move all the code from B
into A
, but falling short when it comes to the database.
B
will be deleted, so it'd be best if the migration lived entirely in A
. That way, anyone can pull the latest code and run manage.py migrate
and it will work on local machines even after B
is deleted.
However, the data still needs to be migrated from B
to A
when running the migration on the production database.
My attempts
I tried inlining B
's models in the migration, querying them (if they exist), then saving new objects using the new models. This is a technique I've used with SQLAlchemy before. The only problem is that Django then adds these temporary models to django_contenttype
and tells me "The following content types are stale and need to be deleted" the next time I run a migration. (I also don't know if Django does anything else I might have missed.)
I also tried setting db_table
to the old app's database table as suggested here, but then the table doesn't exist when running locally from scratch. If I include a CreateModel
migration, then I get django.db.utils.OperationalError: table "b_model" already exists
when migrating on an existing database.
Any ideas?