0

I have seen this in Stack overflow so many times, but i don't know how it relates to the problem i am facing. I am using django 1.11

Here is the full error:

    Traceback (most recent call last):
  File "/Users/kaijieang/Coding/MyLife/MyLife/ministry/views/youth.py", line 1, in <module>
    from ministry.models import Caregroup
  File "/Users/kaijieang/Coding/MyLife/MyLife/ministry/models/__init__.py", line 1, in <module>
    from .attendance import Attendance
  File "/Users/kaijieang/Coding/MyLife/MyLife/ministry/models/attendance.py", line 3, in <module>
    from MyLife.models.base_model import BaseModel
  File "/Users/kaijieang/Coding/MyLife/MyLife/MyLife/models/__init__.py", line 1, in <module>
    from MyLife.models import base_model as BaseModel
  File "/Users/kaijieang/Coding/MyLife/MyLife/MyLife/models/base_model.py", line 4, in <module>
    class BaseModel(models.Model):
  File "/Users/kaijieang/Coding/MyLife/MyLife/MyLife/models/base_model.py", line 5, in BaseModel
    created = models.DateField('Date Created', auto_now_add=True)
  File "/anaconda3/envs/MyLife/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 1185, in __init__
    super(DateField, self).__init__(verbose_name, name, **kwargs)
  File "/anaconda3/envs/MyLife/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 172, in __init__
    self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "/anaconda3/envs/MyLife/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/anaconda3/envs/MyLife/lib/python3.6/site-packages/django/conf/__init__.py", line 39, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

I tried to run this file as part of testing something out:

from ministry.models import Caregroup


def save_model():
    cg = Caregroup(name='a', alias='v', school='c', size=20)

    cg.save()

I am trying something out on a pyCharm IDE and i ran into such an error. May i know what is causing this error? My settings have been properly configured:

wsgi.py:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MyLife.settings")
AKJ
  • 749
  • 6
  • 29

1 Answers1

0

you just need to run

$ export {path_to_bashfile} DJANGO_SETTINGS_MODULE="MyLife.settings"

in terminal and it will work.

enter image description here

Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
  • It still doesnt work. I suspect the issue lies with me being unable to a python file within the app folder directly. – AKJ Dec 22 '17 at 08:08
  • Which part of the script? I am not sure which part you need to see, btu i have provided what i think is the issue – AKJ Dec 22 '17 at 10:30