As business requirements change, so must software. So, sometimes the names of your Django apps will come to no longer make sense. This short tutorial will go through how to rename an existing app without any pain or data loss.
Rename the app folder. For this example,"old_app" is our old name and "new_app" is our new name".
Update all imports referencing the old folder to reference the new.
For example:
Update old app name references within the Django migrations.
Example changes you'll likely have to make:
Make a commit at this point.
Then, however you run your application migrations in a deployed environment, run django_rename_app before you run your migrations in that process.
i.e Before "python manage.py migrate --noinput", as the example below shows.
This will update the app name in the following internal Django database tables:
And rename the prefix of all of your tables to start with your new app name, rather than the old one.
Deploy your project!
You may safely deploy multiple times as the django_rename_app command will only have any effect the first time it is executed.
After deployment give your database and application a manual check over and then remove django_rename_app from your project.
That's all folks. If you have any other tips or tricks to share, we'd love to hear them in the comments!