After using models.Model on class - 'ImproperlyConfigured' error Django

  1. I just started a new project in django, I run the command ‘django-admin startproject + project_name’, and ‘python manage.py startapp + app_name’.
    It creates a project and app.

  2. I also added my new app to the settings INSTALLED_APPS.

2.After that I tried to create my first module on ‘modules.py’ file on my app, but when I do it and run the file, it gives me this error message:


The entire error message says: " django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. "

I created a few projects before, and never saw this problem.

I discovered that if I dont use the ‘models.Model’ on my class, it does not gives me this error.

Someone knows what it is about? I didnt change anything on settings.py file, just added the app name. Maybe its normal to have this error message, when we run the ‘modules.py’ file, and we should just ignore it?

Thank you in advance!

you’re trying to run the models file, but you should be running the project instead. check your run configurations at the top, left to the run button. The dropdown should have selected the django project

2 Likes

So this is a normal error message that appears to everyone who tries to run the models file instead of running the project?

Yes, it would be.

Django is a framework - by this I mean that it’s Django that is running your code, your code isn’t running / controlling Django. What you’re actually writing can be thought of as plugins to Django, and so it’s Django that has to create your model classes.

1 Like