Home > Blockchain >  Why I get error raise ImproperlyConfigured
Why I get error raise ImproperlyConfigured

Time:07-12

I want to add info in database using django-seed.

seed.py

from django_seed import Seed
from models import Employee


seeder = Seed.seeder()
seeder.add_entity(Employee, 5)
inserted_pks = seeder.execute()

When I try to start command: python3 seed.py

I've got this error:

Traceback (most recent call last):
  File "seed.py", line 2, in <module>
    from models import Employee
  File "/home/kaucap/test/myproject/app_worker/models.py", line 4, in <module>
    class Employee(models.Model):
  File "/home/kaucap/test/venv/lib/python3.8/site-packages/django/db/models/base.py", line 127, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/home/kaucap/test/venv/lib/python3.8/site-packages/django/apps/registry.py", line 260, in get_containing_app_config
    self.check_apps_ready()
  File "/home/kaucap/test/venv/lib/python3.8/site-packages/django/apps/registry.py", line 137, in check_apps_ready
    settings.INSTALLED_APPS
  File "/home/kaucap/test/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 87, in __getattr__
    self._setup(name)
  File "/home/kaucap/test/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 67, 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 explain why I have this error and how I can fix it?

CodePudding user response:

python3 seed.py started python without Django settings.

if you are want to start seed.py in Django "environment",

in your django-pproject folder:

python3 manage.py shell

Django shell starts, and in shell:

import seed.py

If you see the same error - you have not created any Django project yet.

  • Related