Skip to content

Instantly share code, notes, and snippets.

@Aperyon
Created March 6, 2018 18:01
Show Gist options
  • Save Aperyon/e8386b62e2fc7e401b4b0e22ff4a3514 to your computer and use it in GitHub Desktop.
Save Aperyon/e8386b62e2fc7e401b4b0e22ff4a3514 to your computer and use it in GitHub Desktop.

Step 1

Rename tables of moved models in database only

  • Start new app
  • add new app in config
  • move models
  • adjust references in models, admins, views, serializers, forms, tests etc.
  • run makemigrations
  • run makemigrations --empty old_app
  • the order of dependency is intial, custom, auto-generated
  • in custom: modify database table names with AlterModelTable with database_operations

Step 2:

Create models in new_app only at state level the database level is ready to use because of the rename in step 1

  • in new app initial, modify the migration to work only on django state level

Step 3:

Alter Other models pointing to this one at both state and database level Delete is not necessary because the table does not exist anymore Alter is required, to let both django and the database know where to look for relations RemoveField on the old model needs to be removed from the migration. The table it would want to remove the field from does not exist anymore

  • old app auto generated migration should depend on custom made and on new_app intial
  • old app auto generated should not delete anything, only alter

Step 4:

Remove models from the old_app at state level. Database level deletion happend in step 1

  • the delete part cut from the previous bulletpoint should be pasted into a new empty migration in the old_app as a state_operation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment