django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TAB LESPACE, but settings are not configured
<p>Iâm using Django 1.9.1 with Python 3.5.2 and I'm having a problem running a Python script that uses Django models.</p>

<pre><code>C:\Users\admin\trailers&gt;python load_from_api.py
Traceback (most recent call last):
  File "load_from_api.py", line 6, in &lt;module&gt;
    from movies.models import Movie
  File "C:\Users\admin\trailers\movies\models.py", line 5, in &lt;module&gt;
    class Genre(models.Model):
  File "C:\Users\admin\trailers\movies\models.py", line 6, in Genre
    id = models.CharField(max_length=10, primary_key=True)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\models\fi
elds\__init__.py", line 1072, in __init__
    super(CharField, self).__init__(*args, **kwargs)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\models\fi
elds\__init__.py", line 166, in __init__
    self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\conf\__init_
_.py", line 55, in __getattr__
    self._setup(name)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\conf\__init_
_.py", line 41, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TAB
LESPACE, but settings are not configured. You must either define the environment
 variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing s
ettings.
</code></pre>

<p>here's the script:</p>

<pre><code>#!/usr/bin/env python
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "trailers.settings")
os.environ["DJANGO_SETTINGS_MODULE"] = "trailers.settings"
import django
django.setup()
import tmdbsimple as tmdb
from movies.models import Movie

#some code...
</code></pre>

<p>I can't really figure out what's wrong. Any help is appreciated!</p>

<p>I figured out how to run it without changing the script and that's by using</p>

<p><code>python manag.py shell</code></p>

<p>and then </p>

<p><code>exec(open('filename').read())</code></p>

<p>that seemed to work just fine.</p>

python django