我已经多次在Stack溢出中看到过这种情况,但我不知道它与我面临的问题有什么关系。我正在使用django 1.11
以下是完整错误:
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.
我尝试将此文件作为测试内容的一部分运行:
from ministry.models import Caregroup
def save_model():
cg = Caregroup(name='a', alias='v', school='c', size=20)
cg.save()
我在pyCharm IDE上尝试了一些东西,我遇到了这样的错误。我可以知道导致此错误的原因是什么吗?我的设置已正确配置:
wsgi.py:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MyLife.settings")