How to change Django application name?

I changed the name of the application in Django, renaming its folder, import and all its links (templates / indexes). But now I get this error when I try to run python manage.py runserver

 Error: Could not import settings 'nameofmynewapp.settings' (Is it on sys.path?): No module named settings 

How can I debug and solve this error? Any clues?

+79
python django
Dec 06 2018-11-12T00:
source share
3 answers

To change the application name in Django, follow these steps:

  • Rename the folder located in the root directory of the project
  • Change any links to your application in your dependencies, i.e. views.py , urls.py , 'manage.py' and settings.py application files.
  • Change the django_content_type database django_content_type following command: UPDATE django_content_type SET app_label='<NewAppName>' WHERE app_label='<OldAppName>'
  • Also, if you have models, you will have to rename the model tables. For postgres, use ALTER TABLE <oldAppName>_modelName RENAME TO <newAppName>_modelName . For mysql, too, I think this is the same (as @null_radix mentioned)
  • (For Django> = 1.7) Refresh the django_migrations table to avoid re-starting previous migrations: UPDATE django_migrations SET app='<NewAppName>' WHERE app='<OldAppName>' . Note : there is some debate (in the comments) if this step is necessary for Django 1.8+; If anyone knows for sure, please update here.
  • If your models.py meta tag contains app_name , be sure to rename it too (mentioned by @will).
  • If you have namespaced your static or templates folders inside your application, you will also need to rename them. For example, rename old_app/static/old_app to new_app/static/new_app .
  • To rename django models you will need to change the django_content_type.name entry in the database. For postgreSQL use UPDATE django_content_type SET name='<newModelName>' where name='<oldModelName>' AND app_label='<OldAppName>'

Meta-point (if virtualenv is used): It is worth noting that if you rename the directory containing your virtualenv, there will probably be several files in your env that contain an absolute path and also need to be updated. If you get errors such as ImportError: No module named ... , this could be a criminal. (thanks to @danyamachine for providing this).

Other links:, you can also link to the links below for a more complete image

  • Rename an application using Django and South
  • How to transfer a model from one django application to a new one?
  • How to change Django application name?
  • Reverse Migration with Django South
  • Easiest way to rename a model using Django / South?
  • Python code (thanks to A.Raouf ) to automate the above steps (inactive code. You have been warned!)
  • Python code (thanks to rafaponieman ) to automate the above steps (inactive code. You have been warned!)
+158
Dec 06 2018-11-12T00:
source share

New in Django 1.7 is an application registry that stores configuration and provides introspection. This mechanism allows you to change several attributes of the application.

The main thing I want to do is that renaming the application is not always necessary: โ€‹โ€‹when configuring the application, conflicting applications can be resolved. But also a way if your application needs a friendly name.

As an example, I want to call my user feedback survey application. This happens as follows:

Create the apps.py file in the polls directory:

 from django.apps import AppConfig class PollsConfig(AppConfig): name = 'polls' verbose_name = "Feedback from users" 

Add the default application configuration to polls/__init__.py :

 default_app_config = 'polls.apps.PollsConfig' 

For more application configuration: https://docs.djangoproject.com/en/1.7/ref/applications/

+21
Dec 01 '14 at 9:31
source share

If you use PyCharm and stop working on the project after renaming:

  • Edit the Run / Debug configuration and change the DJANGO_SETTINGS_MODULE environment variable as it includes the name of your project.
  • Go to Settings / Languages โ€‹โ€‹and Frames / Django and update the location of the settings file.
+2
Sep 29 '17 at 19:56 on
source share



All Articles