vendredi 18 décembre 2015

Can't import Django model - ImproperlyConfigured

I want to process some data from the database in Django. The thing is that it raises some exception when it tries to import models.

# -*- coding: utf-8 -*- 

from uploading import models

# lang = models.Languages.objects.get(language_shortcut='EN')
# print lang.price_per_word

I've already do migrations and insert some data using Django admin.

SETTINGS.PY:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

This is the exception:

Traceback (most recent call last):
  File "C:/Users/Milano/PycharmProjects/mysite/uploading/scripts/calculator.py", line 3, in <module>
    from uploading import models
  File "C:\Users\Milano\PycharmProjects\mysite\uploading\models.py", line 3, in <module>
    class Languages(models.Model):
  File "C:\Users\Milano\PycharmProjects\mysite\uploading\models.py", line 4, in Languages
    language = models.CharField(max_length=100)
  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.

Whats wrong with that code?

Aucun commentaire:

Enregistrer un commentaire