title: DB error: django.core.exceptions.ImproperlyConfigured
body: <p>Getting this error when trying to create a fixture and run next command in terminal:</p>
  
  <pre><code>django-admin.py dumpdata data.json
  </code></pre>
  
  <p>Full traceback:</p>
  
  <pre><code>(project)litwisha@litwisha:~/PycharmProjects/test_project$ django-admin.py dumpdata data.json
  Traceback (most recent call last):
    File "/home/litwisha/.virtualenvs/project/bin/django-admin.py", line 5, in &lt;module&gt;
      management.execute_from_command_line()
    File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
      utility.execute()
    File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/base.py", line 402, in run_from_argv
      connections.close_all()
    File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/utils.py", line 258, in close_all
      for alias in self:
    File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/utils.py", line 252, in __iter__
      return iter(self.databases)
    File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/utils/functional.py", line 60, in __get__
      res = instance.__dict__[self.name] = self.func(instance)
    File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/utils.py", line 151, in databases
      self._databases = settings.DATABASES
    File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
      self._setup(name)
    File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
      % (desc, ENVIRONMENT_VARIABLE))
  django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
  </code></pre>
  
  <p>Tried this <a href="https://stackoverflow.com/a/15556596/3525271">solution</a>, but doesn't work:</p>
  
  <p>When writing in shell: </p>
  
  <pre><code>from django.conf import settings
  settings.configure()
  </code></pre>
  
  <p>get error: </p>
  
  <pre><code>RuntimeError: Settings already configured.
  </code></pre>
  
  <p>Maybe it because I use <code>virtualenv</code>? But I tried it without <code>virtualenv</code>, but it doesn't work. I use IDE <code>PyCharm</code></p>
  
  <pre><code>settings.py:
  """
  Django settings for test_project project.
  
  Generated by 'django-admin startproject' using Django 1.8.3.
  
  For more information on this file, see
  https://docs.djangoproject.com/en/1.8/topics/settings/
  
  For the full list of settings and their values, see
  https://docs.djangoproject.com/en/1.8/ref/settings/
  """
  
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  import os
  
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  
  
  # Quick-start development settings - unsuitable for production
  # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
  
  # SECURITY WARNING: keep the secret key used in production secret!
  SECRET_KEY = 'r1n@)rahbrh6t1hb-mn_83c^7ai@ij&amp;7d8m8mo7tdm&amp;5q#o5t&amp;'
  
  # SECURITY WARNING: don't run with debug turned on in production!
  DEBUG = True
  
  ALLOWED_HOSTS = []
  
  
  # Application definition
  
  INSTALLED_APPS = (
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'app',
  )
  
  MIDDLEWARE_CLASSES = (
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
      'django.middleware.security.SecurityMiddleware',
  )
  
  ROOT_URLCONF = 'test_project.urls'
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [os.path.join(BASE_DIR,  'templates'),],
          'APP_DIRS': True,
          'OPTIONS': {
              'context_processors': [
                  'django.template.context_processors.debug',
                  'django.template.context_processors.request',
                  'django.contrib.auth.context_processors.auth',
                  'django.contrib.messages.context_processors.messages',
              ],
          },
      },
  ]
  
  WSGI_APPLICATION = 'test_project.wsgi.application'
  
  
  # Database
  # https://docs.djangoproject.com/en/1.8/ref/settings/#databases
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
          'NAME': 'test1',
          'USER': 'postgres',
          'PASSWORD': '1111',
          'HOST': '127.0.0.1',
          'PORT': '5432'
      }
  }
  
  
  # Internationalization
  # https://docs.djangoproject.com/en/1.8/topics/i18n/
  
  LANGUAGE_CODE = 'en-us'
  
  TIME_ZONE = 'UTC'
  
  USE_I18N = True
  
  USE_L10N = True
  
  USE_TZ = True
  
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/1.8/howto/static-files/
  
  STATIC_URL = '/static/'
  </code></pre>