3

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?

Community
  • 1
  • 1
Joe
  • 14,782
  • 10
  • 57
  • 69
  • The linked question is marked as a duplicate of this one: http://stackoverflow.com/questions/1258130/how-do-i-migrate-a-model-out-of-one-django-app-and-into-a-new-one. Seems to have a more robust way of solving this problem. – Symmetric Nov 01 '16 at 18:24

0 Answers0