How to Rename Application in Django

Posted on

In Django framework, in order to rename the application which is already created is very easy. The process is executed by renaming the folder which is representing the application. The following is the actual information concerning on the application :

1. There is an already running application named ‘apps’.

2. The application is going the renamed into another name. The name of the application is ‘application’.

3. Renaming application can be done by executing the following command :

mv apps application

It can be shown as follows :

user@hostname:~/project/apps$ mv apps application

The following is the actual folder location which is taken from the project folder :

user@hostname:~/project/apps$ tree -L 2
├── db.sqlite3
├── application
│   ├──
│   ├── __init__.pyc
│   ├──
│   ├── settings.pyc
│   ├──
│   ├── urls.pyc
│   ├──
│   └── wsgi.pyc
└── module
    ├── admin.pyc
    ├── apps.pyc
    ├── __init__.pyc
    ├── migrations
    ├── models.pyc
    ├── static
    ├── templates
    ├── urls.pyc
    └── views.pyc

5 directories, 23 files

4. But the consequences is every table which is represented inside the associated application must be changed. For instance, if there is a class named ‘task’ defined in a model file named as shown below :

from __future__ import unicode_literals
from datetime import datetime

from django.db import models

# Create your models here.

class Task(models.Model):
title = models.CharField(max_length=200)
text = models.TextField()
created_at = models.DateTimeField(
def __str__(self):
return self.title

The above class named ‘Task’, previously it is located in an application named ‘apps’ and it is changed into an application named ‘application’. It is made just to explain the scenario. Below is the actual step which is actually taken to change the table name. This is an obvious step because executing the command ‘python makemigrations’ and ‘python migrate’ to create a table which is represented by a class defined in the will actually takes the application name as part of the table name. So, in order to make the application work perfectly after renaming it, just re-execute the command and the table will also be renamed. The pattern of the table is ‘appname_classname’. Below is the example of it :

user@hostname:~/project/apps$ python migrate
Operations to perform:
Apply all migrations: account, network, service, sessions, admin, sites, auth, server, contenttypes, socialaccount
Running migrations:
No migrations to apply.
Your models have changes that are not yet reflected in a migration, and so won't be applied.
Run ' makemigrations' to make new migrations, and then re-run ' migrate' to apply them.
The following content types are stale and need to be deleted:

application | apps

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

Type 'yes' to continue, or 'no' to cancel: yes

One thought on “How to Rename Application in Django

Leave a Reply