django rename app

Posted Over 5 years ago. Visible to the public. Draft.

Before renaming

Always migrate databases before changing the app name.

manage.py makemigrations

when you see the following message then it is safe to proceed with renaming the app.

No changes detected

Fixed table names

For this case it is assumed the table names are fixed in models.py

Rename and Loose migration

  1. remove migrations from db:
manage.py migrate --fake old_app_name zero
  1. remove migration files from app
find old_app_name -path "*/migrations/*.py" \
     -not -name "__init__.py" \
     -delete
find old_app_name -path "*/migrations/*.pyc"  \
     -delete
  1. rename folder and update all references to app. Take special note of updating '''views.py''', '''urls.py''', and '''settings.py'''

  2. Edit the database table '''django_content_type'''. For this step you need to rename the old app name with the new app name in the column 'app_label'

  3. reset migrations

manage.py makemigrations
manage.py migrate --fake-initial
manage.py showmigrations

Reference

Rename Steps Show archive.org snapshot
django reset migrations

Cuauhtemoc
Last edit
Over 5 years ago
Cuauhtemoc
Posted by Cuauhtemoc to Python Django (2018-08-03 00:17)