【发布时间】:2019-06-27 20:20:51
【问题描述】:
问题
我试图使用fixtures 来填充我的数据库,因此我首先阅读了loaddata 的文档,默认情况下,它会在每个应用程序内的fixtures 目录中查找fixtures。我的问题是,当我运行 python manage.py loaddata 时出现错误,但是当我给它提供 teams.yaml 的路径时,它工作正常。我需要设置一些东西才能让它工作吗?
文档
https://docs.djangoproject.com/en/1.11/howto/initial-data/#where-django-finds-fixture-files
错误
usage: manage.py loaddata [-h] [--version] [-v {0,1,2,3}]
[--settings SETTINGS] [--pythonpath PYTHONPATH]
[--traceback] [--no-color] [--database DATABASE]
[--app APP_LABEL] [--ignorenonexistent] [-e EXCLUDE]
fixture [fixture ...]
manage.py loaddata: error: No database fixture specified. Please provide the path of at least one fixture in the command line.
团队应用目录
team
├── admin.py
├── apps.py
├── fixtures
│ └── teams.yaml
├── __init__.py
├── migrations
│ ├── 0001_initial.py
│ ├── 0002_auto_20190204_0438.py
│ ├── 0003_remove_team_team_name.py
│ ├── `enter code here`0004_team_team_name.py
│ ├── __init__.py
│ └── __pycache__
│ ├── 0001_initial.cpython-36.pyc
│ ├── 0002_auto_20190204_0438.cpython-36.pyc
│ ├── 0003_remove_team_team_name.cpython-36.pyc
│ ├── 0004_team_team_name.cpython-36.pyc
│ └── __init__.cpython-36.pyc
├── models.py
├── __pycache__
│ ├── admin.cpython-36.pyc
│ ├── apps.cpython-36.pyc
│ ├── __init__.cpython-36.pyc
│ └── models.cpython-36.pyc
├── tests.py
└── views.py
型号
from django.db import models
class Team(models.Model):
team_name = models.CharField(max_length=32)
team_description = models.TextField(max_length=512, blank=False)
class Meta:
permissions = (
('create_team', 'Can create a team'),
)
夹具(teams.yaml)
- model: team.Team
pk: 1
fields:
team_name: team_name_example
team_descrition: team_description_example
【问题讨论】: