django - 了解 Django 初始数据装置

标签 django django-fixtures

问题

  • initial_data.json 装置位于项目目录内但不在 Django 搜索装置的三个指定位置之一时,为什么 Django 会自动加载它?

配置信息

  1. 我尚未在 settings.py 中设置 FIXTURE_DIRS 设置
  2. Django 1.2.1

Django 关于固定位置的文档

What's a "Fixture" Django 的 django-admin.py and manage.py 部分文档说明:

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.

最佳答案

initial_data实际上是属于syncdb的行为。您引用的是 loaddata 在查询时将查找的默认位置。 initial_data.json 由syncdb 选项检测并传递给loaddata。我同意这有点令人困惑,但实际上您正在将一般夹具加载行为(loaddata)与自动夹具加载行为(syncdb)混合在一起。

希望这有帮助。

关于django - 了解 Django 初始数据装置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3111600/

相关文章:

django - 如何从所有应用程序加载 Django 装置?

django - 使用现有数据将数据导入 Django 模型?

python - 如何通过 package_name.module_name.class_name "path"实例化类

Django 按字典过滤模型

django - 如何防止 Django 自动转换日期时间

django - 来自 rest_framework modelSerializer 的模型方法

Django 固定装置,加载大量数据

symfony - 如何在 Symfony 中两个表之间存在关系的地方创建夹具?

django - 让loaddata忽略或禁用post_save信号

Django反向查询集包含列表中的所有值