问题
- 当
initial_data.json
装置位于项目目录内但不在 Django 搜索装置的三个指定位置之一时,为什么 Django 会自动加载它?
配置信息
- 我尚未在 settings.py 中设置
FIXTURE_DIRS
设置 - Django 1.2.1
Django 关于固定位置的文档
What's a "Fixture" Django 的 django-admin.py and manage.py 部分文档说明:
Django will search in three locations for fixtures:
- In the fixtures directory of every installed application
- In any directory named in the FIXTURE_DIRS setting
- 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.
最佳答案
initial_data实际上是属于syncdb的行为。您引用的是 loaddata 在查询时将查找的默认位置。 initial_data.json 由syncdb 选项检测并传递给loaddata。我同意这有点令人困惑,但实际上您正在将一般夹具加载行为(loaddata)与自动夹具加载行为(syncdb)混合在一起。
希望这有帮助。
关于django - 了解 Django 初始数据装置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3111600/