0

I'm attempting to use django-admin.py loaddata to seed a database on a dev server. I am using django 1.7.1. After symlinking the file to my project, when I tried to run the command I got this error:

django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Which lead me to this question. So I attempted the recommended solution of export DJANGO_SETTINGS_MODULE=inventory_manage.settings. However when I tried to run the loaddata command again, I was met with this ImportError:

ImportError: Could not import settings 'inventory_manager.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named inventory_manager.settings

Further research lead to checking if my site was on the sys.path for my virtualenv. Which it was:

/Users/Aaron/Development/inventory-manager <--This is it
/Users/Aaron/.virtualenvs/inventorymgr/lib/python27.zip
/Users/Aaron/.virtualenvs/inventorymgr/lib/python2.7
/Users/Aaron/.virtualenvs/inventorymgr/lib/python2.7/plat-darwin
/Users/Aaron/.virtualenvs/inventorymgr/lib/python2.7/plat-mac
/Users/Aaron/.virtualenvs/inventorymgr/lib/python2.7/plat-mac/lib-scriptpackages
/Users/Aaron/.virtualenvs/inventorymgr/Extras/lib/python
/Users/Aaron/.virtualenvs/inventorymgr/lib/python2.7/lib-tk
/Users/Aaron/.virtualenvs/inventorymgr/lib/python2.7/lib-old
/Users/Aaron/.virtualenvs/inventorymgr/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
    /Users/Aaron/.virtualenvs/inventorymgr/lib/python2.7/site-packages

Yet when I run the loaddata command, I'm still getting the same ImportError. Any ideas?

Community
  • 1
  • 1
Aaron
  • 2,367
  • 3
  • 25
  • 33

2 Answers2

2

You should only ever use django-admin.py to create the project. After that, always use manage.py, since it points to your actual project settings.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
2

You need to already be inside your python project root directory, and you should use python manage.py loaddata; which will setup the environment for you correctly:

In addition, manage.py is automatically created in each Django project. manage.py is a thin wrapper around django-admin that takes care of several things for you before delegating to django-admin:

  • It puts your project’s package on sys.path.
  • It sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project’s settings.py file.
  • It calls django.setup() to initialize various internals of Django.
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284