Django Standalone Script
<p>I am trying to access my Django (v1.10) app DB from another python script and having some trouble doing so.</p>

<p>This is my file and folder structure:</p>

<pre><code>store
 store
   __init.py__
   settings.py
   urls.py
   wsgi.py
 store_app
   __init.py__
   admin.py
   apps.py
   models.py
   ...
 db.sqlite3
 manage.py

other_script.py
</code></pre>

<p>In accordance with <a href="https://docs.djangoproject.com/en/1.10/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage" rel="nofollow">Django's documentations</a> my <code>other_script.py</code> looks like this:</p>

<pre><code>import django
from django.conf import settings

settings.configure(DEBUG=True)
django.setup()

from store.store_app.models import MyModel
</code></pre>

<p>But it generates a runtime error:</p>

<pre><code>RunTimeError: Model class store.store_app.models.MyModel doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
</code></pre>

<p>I should note that my <code>INSTALLED_APPS</code> list contains <code>store_app</code> as its last element.</p>

<p>If instead I try to pass a config like this:</p>

<pre><code>import django
from django.conf import settings
from store.store_app.apps import StoreAppConfig

settings.configure(StoreAppConfig, DEBUG=True)
django.setup()

from store.store_app.models import MyModel
</code></pre>

<p>I get:</p>

<pre><code>AttributeError: type object 'StoreAppConfig has no attribute  'LOGGING_CONFIG'.
</code></pre>

<p>If I edit <code>settings.py</code> and add <code>LOGGING_CONFIG=None</code> I get another error about another missing attribute, and so on.</p>

<p>Any suggestions will be appreciated.   </p>

<p>Try this</p>

<pre><code>import sys, os, django
sys.path.append("/path/to/store") #here store is root folder(means parent).
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "store.settings")
django.setup()

from store_app.models import MyModel
</code></pre>

<p>This script you can use anywhere in your system.</p>

python django