Search code examples
djangodjango-fixtures

Understanding Django initial_data fixture


Question

  • Why does Django automatically load the initial_data.json fixture when it's located inside the project directory but not located in one of the three specified locations that Django searches for fixtures?

Configuration Information

  1. I have not set the FIXTURE_DIRS setting in settings.py
  2. Django 1.2.1

Django's Documentation Regarding Fixture Locations

The What's a "Fixture" section of Django's django-admin.py and manage.py documentation states:

Django will search in three locations for fixtures:

  1. In the fixtures directory of every installed application
  2. In any directory named in the FIXTURE_DIRS setting
  3. In the literal path named by the fixture

Django will load any and all fixtures it finds in these locations that match the provided fixture names.


Solution

  • initial_data is actually behaviour belonging to syncdb. What you are citing is the default places loaddata will look for when queried. initial_data.json is detected by the syncdb option and passed to loaddata. I agree it's a bit confusing, but you are actually mixing general fixture loading behaviour (loaddata) with automatic fixture loading behaviour (syncdb).

    Hope this helps.