Django ImproperlyConfigured

I'm fairly new to programming and I was learning Python by following the textbook No Starch Python. There is a chapter on Django and I followed the steps of the textbook. However, when I run the program:

from django.db import models

class Topic(models.Model):
    """A topic the user is learning about"""
    text = models.CharField(max_length=200)
    date_added = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        """Return a string representation of the model."""
        return self.text

I will get this error message:

Traceback (most recent call last):
  File "/Users/admin/learning_log2/learning_logs/", line 4, in <module>
    class Topic(models.Model):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/db/models/", line 127, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/apps/", line 260, in get_containing_app_config
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/apps/", line 137, in check_apps_ready
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/conf/", line 92, in __getattr__
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/conf/", line 72, in _setup
    raise ImproperlyConfigured(
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.

Can anyone tell me why it is the case and what can I do? Thank you very much. P.S. I know there is already a post on this but I tried what was written without any results. Also, I'm on macOS High Sierra version 10.13.6 if this information is relevant.

I tried whatever I could find on the internet but nothing seems to work. I don't even have a fundamental understanding of the problem.

I don't even have a fundamental understanding of the problem

Since you're defining a model, Django assumes that you might want to store instances of that model in a database.

To do that, Django needs to know the connection details for your chosen database, and those details are stored in the module.

You didn't tell Django where to find that module.

You need to specify the django app name in the file before start using it.

You were created a Django Application before creating this model 'Topic' with a command

python startapp core 

you need to provide the appname (in the above case it is 'core') under file in the array like bellow

'core' #new app name


Back to Top