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.
-
Go to your Project and click the Edit Configuration Settings.
-
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. -
Then add your new project name
newname
, which contains thesettings.py
file.
That’s it.
- [Django]-Mixin common fields between serializers in Django Rest Framework
- [Django]-Resource temporarily unavailable using uwsgi + nginx
- [Django]-Where to put business logic in django
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
- [Django]-No URL to redirect to. Either provide a url or define a get_absolute_url method on the Model
- [Django]-How to specify an IP address with Django test client?
- [Django]-Django CMS fails to synch db or migrate
1👍
Look inside “Run/Debug Configurations, “Environment”, and under “Environment Variables”. oldname might be found in one of those.
- [Django]-Django Footer and header on each page with {% extends }
- [Django]-Django simple_tag and setting context variables
- [Django]-How to loop over form field choices and display associated model instance fields
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:
Hope it helps?
- [Django]-How to server HTTP/2 Protocol with django
- [Django]-How to make two django projects share the same database
- [Django]-Using Cloudfront with Django S3Boto
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.
- [Django]-Django CMS fails to synch db or migrate
- [Django]-Django models: Only permit one entry in a model?
- [Django]-Using the reserved word "class" as field name in Django and Django REST Framework
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.
- [Django]-Adding css class to field on validation error in django
- [Django]-Django: list all reverse relations of a model
- [Django]-How to make an auto-filled and auto-incrementing field in django admin
0👍
You need to also change the pycharm settings .iml and .xml references to ensure your project can read & execute manage.py tasks.
- [Django]-Django celery task: Newly created model DoesNotExist
- [Django]-Alowing 'fuzzy' translations in django pages?
- [Django]-Django models: Only permit one entry in a model?
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
- [Django]-Django REST Framework: how to substitute null with empty string?
- [Django]-Are sessions needed for python-social-auth
- [Django]-Celery discover tasks in files with other filenames
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.
- [Django]-Choose test database?
- [Django]-How to show processing animation / spinner during ajax request?
- [Django]-How do I use django rest framework to send a file in response?
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.
- [Django]-Jquery template tags conflict with Django template!
- [Django]-CORS error while consuming calling REST API with React
- [Django]-How to run celery as a daemon in production?
0👍
I have manually changed the project name. If that is fine then checkout my answer https://stackoverflow.com/a/63303738/9384511
- [Django]-How do you change the collation type for a MySQL column?
- [Django]-How do Django models work?
- [Django]-POST jQuery array to Django
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.
- [Django]-Filtering using viewsets in django rest framework
- [Django]-How to format time in django-rest-framework's serializer?
- [Django]-Django Rest JWT login using username or email?