DJANGO 1.11 - 无法找到灯具

问题描述 投票:2回答:2

Problem

我试图用灯具来填充我的数据库,所以我就开始通过对loaddata,默认情况下文档阅读,它看起来在每个应用程序的固定装置内的灯具目录。我的问题是,当我运行python manage.py loaddata我得到一个错误,但是当我给它的路径teams.yaml它工作正常。我是否需要安装的东西,它的工作?

Documentation

https://docs.djangoproject.com/en/1.11/howto/initial-data/#where-django-finds-fixture-files

Error

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 App Dir

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

Model

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'), 
        )

Fixture (teams.yaml)

- model: team.Team
  pk: 1
  fields:
    team_name: team_name_example
    team_descrition: team_description_example
django django-fixtures
2个回答
0
投票

错误说:No database fixture specified. Please provide the path of at least one fixture in the command line.

您需要提供fixturename命令loaddata,你的情况:

python manage.py loaddata team

这是在文档,默认情况下Django会考虑灯具的目录你的应用程序中与指定fixturename规定。另外,命令接受./path/to/fixtures/它覆盖灯具目录的搜索。


0
投票

如果您在定义设置FIXTURE_DIRS文件,使Django的找到你的夹具,其中有有。

settings.朋友

FIXTURE_DIRS = [
    os.path.join(BASE_DIR, 'fixtures')
]
# statements

Reference

© www.soinside.com 2019 - 2024. All rights reserved.