Django似乎只允许一个项目的模型

时间:2015-05-26 22:18:06

标签: python django sqlite

我在Django工作,我在一个项目中有2个应用程序(监视和维护)。我似乎无法弄清楚为什么当一个应用程序的models.py工作时,另一个不工作。这是我的调试输出,但似乎没有任何意义,因为我设置了DJANGO_SETTINGS_MODULE。两个应用程序都工作,直到我将模型添加到其中一个。然后“监视器”死了。当我在监视器中更改模型时,维护就发生了这种情况。

调试输出:

    Connected to pydev debugger (build 139.1659)
Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.6\helpers\pydev\pydevd.py", line 2217, in <module>
    globals = debugger.run(setup['file'], None, None)
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.6\helpers\pydev\pydevd.py", line 1643, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:/REPOS/client-product-controller/Web/myproject/maintenance/views.py", line 4, in <module>
    from models import Control
  File "C:/REPOS/client-product-controller/Web/myproject/maintenance\models.py", line 5, in <module>
    class Control(models.Model):
  File "C:/REPOS/client-product-controller/Web/myproject/maintenance\models.py", line 6, in Control
    control_label = models.CharField(max_length=200)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 1081, in __init__
    super(CharField, self).__init__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 161, in __init__
    self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 48, in __getattr__
    self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 42, 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.

这是我的wsgi.py

    import os
# import pdb; pdb.set_trace()

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

application = get_wsgi_application()

和我的维护/ views.py

...    
from models import Control
..

并在我的maintenance / models.py

...
class Control(models.Model):
    control_label = models.CharField(max_length=200)
...

我没有更改维护中的任何代码。刚刚在监视器中发生了SAME错误。我不确定发生了什么变化,但我确实做了迁移和syncdb

0 个答案:

没有答案