django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG

Rasel

I'm getting the below traceback and it seems to be related to changes made in Django 3.0.2? I'd appreciate if someone could explain what I'm doing wrong here.

(myDjangoEnv) D:\Django\django_lectures\first_project>python populate_first_app.py
Traceback (most recent call last):
  File "populate_first_app.py", line 5, in <module>
    django.setup()
  File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
    self._setup(name)
  File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\conf\__init__.py", line 57, in _setup
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Here is my code:

import  os
os.environ.setdefault('DJANGO_SETTING_MODULE', 'first_project.settings')

import django
django.setup()

##FAKER POP SCRIPT
import random
from first_app.models import AccessRecord, Topic, Webpage
from faker import Faker

fakegen = Faker()
topics = ['Search', 'Social', 'Marketplace', 'News', 'Game']

def add_topic():
    t = Topic.objects.get_or_create(top_name = random.choice(topics))[0]
    t.save()
    return t


def populate(N = 5):

    for entry in range(N):

        #get the topic for the entry
        top = add_topic()

        #Create fake data for that entry
        fake_url = fakegen.url()
        fake_date = fakegen.date()
        fake_name = fakegen.company()

        #Create new webpage entry
        webpage = Webpage.objects.get_or_create(topic = top, url= fake_url, name = fake_name)[0]

        #Create a fake AccessRecord for that webpage
        acc_rec = AccessRecord.objects.get_or_create(name = webpage, date = fake_date)[0]


if __name__ == '__main__':
    print("populate Script!")
    populate(20)
    print("populating Complete!")
Brian

You need the set the environment variable DJANGO_SETTINGS_MODULE, not DJANGO_SETTING_MODULE. Note the S at the end of SETTINGS.

Try editing your second line to read

os.environ['DJANGO_SETTINGS_MODULE'] = 'first_project.settings'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured

django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured

django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured

django.core.exceptions.ImproperlyConfigured: Requested setting AUTH_USER_MODEL, but settings are not configured

django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment varia

django.core.exceptions.ImproperlyConfigured

Django.core.exceptions.ImproperlyConfigured:

Django Installed app and ImproperlyConfigured Error: django.core.exceptions.ImproperlyConfigured

django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty

Error message: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty

Issue in django.core.exceptions.ImproperlyConfigured

Python | Docker | Django | django.core.exceptions.ImproperlyConfigured Error

How to fix the error for django 'django.core.exceptions.ImproperlyConfigured' with urls?

Django Celery scheduled task django.core.exceptions.ImproperlyConfigured

django.core.exceptions.ImproperlyConfigured: Django 3.0.1 is not supported

Django channels pytest testing. django.core.exceptions.ImproperlyConfigured. .

django.core.exceptions.ImproperlyConfigured: Field name `id` is not valid for model

django.core.exceptions.ImproperlyConfigured: WSGI application 'application' could not be loaded

django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library

"django.core.exceptions.ImproperlyConfigured:" while doing migrations to posgreSQL

How to resolve "django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: foo" in Django 1.7?

django.core.exceptions.ImproperlyConfigured: Enable 'django.contrib.auth.context_processors.auth'

"Apps aren't loaded yet" and "django.core.exceptions.ImproperlyConfigured" in Django?

Django Error: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module

Can't run django-admin startproject mysite (ubuntu, django.core.exceptions.ImproperlyConfigured)

django.core.exceptions.ImproperlyConfigured: Cannot import ASGI_APPLICATION module 'routing'

DRF throw django.core.exceptions.ImproperlyConfigured when override get_queryset

Django.core.exceptions.ImproperlyConfigured: Error running functional_tests.py

django.core.exceptions.ImproperlyConfigured: Cannot import 'category'. Check that 'api.category.apps.CategoryConfig.name' is correct