[Django]-Changing a project name in django

20👍

I got the same error when changing my project name, the problem is that you’re running the server using PyCharm, isn’t it? Hopefully, you created your project using PyCharm with Django Support. First of all add the below settings to your wsgi.py, asgi.py, and manage.py files,

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'oldname.settings')

to

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'newname.settings')

Then go to your settings.py and change the below settings,

ROOT_URLCONF = 'oldname.urls
WSGI_APPLICATION = 'oldname.wsgi.application'

to

ROOT_URLCONF = 'newname.urls
WSGI_APPLICATION = 'newname.wsgi.application'

If you didn’t get PyCharm‘s Django Support, this solution should be performed otherwise you will get the same error again. You can try this by using some other terminal without getting PyCharm‘s Django Support and running your server with python manage.py runserver command. If your project doesn’t have any other errors you can see this solution is working. Then I realized something wrong with PyCharm‘s Django Support, the help that I have provided is only for those who are using PyCharm‘s Django Support.

  1. Go to your Project and click the Edit Configuration Settings.

    Pycharm Project Configuration

  2. You can see the Environment variable still has the previous values, just click the icon in the corner to edit the DJANGO_SETTINGS_MODULE variable.

    enter image description here

  3. Then add your new project name newname, which contains the settings.py file.

    enter image description here

That’s it.

10👍

make sure you change the name in settings.py , wsgi.py and manage.py

3👍

Theres one main place where a Django app gets its app name and its in

myappname/apps.py

from django.apps import AppConfig


class StorefrontConfig(AppConfig):
    name = 'myappname'

Then in settings.py you can find

INSTALLED_APPS = [
    'myappname',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

]

Once you change the name of your app you want to change it in settings.py and in apps.py

1👍

Look inside “Run/Debug Configurations, “Environment”, and under “Environment Variables”. oldname might be found in one of those.

1👍

I have a solution with Django 2.2 working perfectly. You have renamed the old project to example django_master. Then you need to change in the list of file:

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_master.settings')

application = get_wsgi_application()

## django_master.settings

settings.py

#line 54 

ROOT_URLCONF = 'django_master.urls'

#line 72 django 2.2 default code

WSGI_APPLICATION = 'django_master.wsgi.application'

After this three change your project now run python mange.py runserver

If still not working find with old project name in project directory:

enter image description here

Hope it helps?

1👍

Instead of going through all the steps to change a project, just create a new one. This worked for me using PyCharm on MacOS on a project with no database configured.

  • Create a new directory with the new project name
  • In PyCharm, create a new Django project with the new project name in the directory you just created
  • Copy your apps over from the old project
  • Update the urls.py in the project directory with the changes you made in the old one. You might get away with just copying it to the project. Do a file compare to be sure
  • Update the settings.py with the change to made to the old one. A copy wouldn’t work since the new project name is used in it
  • Copy over the PyCharm app preferences/file watchers. All my other PyCharm preferences settings seem to be global to all PyCharm projects.

Beside being easier to do, the method doesn’t touch your existing project. If it doesn’t work, just delete it.

👤curt

1👍

The best way to achieve this consist of renaming all the occurences of the project name in the wsgi.py, asgi.py, settings.py and manage.py file.

I have created a simple Python script that handles that for any project. This allows for a quick and no mistake process.

Just place the rename.py script inside the main folder of the Django project (same level as manage.py file) and run the script.

0👍

You need to also change the pycharm settings .iml and .xml references to ensure your project can read & execute manage.py tasks.

0👍

You can just run this command. for example if I want change old_project_name to new_project_name In the path that I am
python manage.py rename old_project new new_project

0👍

I am using VSCode an in that I simply made a search of the name I want to change on the project level and replaced it with another name(new name I wanted)!.
It worked without a hiccup.

0👍

Same issue happened in my project. I had to change my project_old_app_name to project_new_app_name. When i change the old to new by using visual studio code replace all method.

i got this error

 ...
    return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 994, in _gcd_import
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
    ModuleNotFoundError: No module named 'project_new_app_name' 

then i came to realised that i have to change the folder/directory app name of my project_old_app_name to project_new_app_name, then it work.

Note:- I got problem of not matching table name as it was named to old_app_table_name. So, In this case (i used sqlite db) i had to do python manage.py migrate and to insert data again. Or We can change all the old_app_name_tablenames to new_app_name_tablenames in sqlite browser.

0👍

I have manually changed the project name. If that is fine then checkout my answer https://stackoverflow.com/a/63303738/9384511

👤ABN

0👍

I just had this issue when I renamed my project. Turned out that I’d renamed everything correctly. It was just that my environment had retained the old environment variable so I had to reset it.

So, for anybody finding this question that thinks they’ve renamed manage.py, all their settings.py, wsgi.py and asgi.py etc.:

run env | grep DJANGO, and make sure DJANGO_SETTINGS_MODULE is either not set at all, or set to the new value. Most likely this is your issue.

Leave a comment