ducin
ducin

Reputation: 26467

django doesn't load initial fixtures while syncdb

I've got a django project with following structure:

/djninja # project dir
  /djninja # main app dir
  /bands # app dir
  /fans # app dir
  /lyrics # app dir

I've created a initial_data.yaml file to make syncdb load fixtures (I prefer YAML format). According to the documentation, I shall put it in any app fixtures subdirectory. And so I did, I had:

/djninja
  /djninja
  /bands
    /fixtures
      - initial_data.yaml
  /fans
  /lyrics

But syncdb was omitting the file. Then I moved it into main project directory:

/djninja
  /djninja
    /fixtures
      - initial_data.yaml
  /bands
  /fans
  /lyrics

And still it is being omitted. I'd like to load fixtures within syncdb command What am I doing wrong?

Upvotes: 2

Views: 1735

Answers (2)

Hamid Nazari
Hamid Nazari

Reputation: 3985

Apparently Django looks for fixtures in apps specified in INSTALLED_APPS that have a models.py in them.

So if your app is missing one, create an empty models.py and Django won't skip looking for fixtures in that app.

Upvotes: 7

kgr
kgr

Reputation: 9948

initial_data.yaml should be picked up as long as:

  • you have pyyaml installed
  • it's located in fixtures directory of one of your apps listed in INSTALLED_APPS (in settings.py)

So, given you have pyyaml it's probably the latter. Please make sure your fixtures directory is inside one of the apps listed in INSTALLED_APPS and you should be up and running.

In case of this layout:

/djninja
  /djninja
  /bands
    /fixtures
      - initial_data.yaml
  /fans
  /lyrics

adding bands to INSTALLED_APPS should do the trick, given bands is a valid package and is on PYTHONPATH.

If you'd like Django to look for fixtures in some other directory, you can follow the advice given in "Where Django finds fixture files" subsection of the docs and use the FIXTURE_DIRS setting, making it a list of extra directories to look in.

Upvotes: 1

Related Questions