- change the names of old models to ‘model_name_old’
- makemigrations
- make new models named ‘model_name_new’ with identical relationships on the related models
(eg. user model now has user.blog_old and user.blog_new)
- makemigrations
- write a custom migration that migrates all the data to the new model tables
- test the hell out of these migrations by comparing backups with new db copies before and after running the migrations
- when all is satisfactory, delete the old models
- makemigrations
- change the new models to the correct name ‘model_name_new’ -> ‘model_name’
- test the whole slew of migrations on a staging server
- take your production site down for a few minutes in order to run all migrations without users interfering
Do this individually for each model that needs to be moved.
I wouldn’t suggest doing what the other answer says by changing to integers and back to foreign keys
There is a chance that new foreign keys will be different and rows may have different IDs after the migrations and I didn’t want to run any risk of mismatching ids when switching back to foreign keys.