gpt4 book ai didi

DJANGO 1.11 - 找不到固定装置

转载 作者:行者123 更新时间:2023-12-05 06:28:12 27 4
gpt4 key购买 nike

问题

我试图使用 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

最佳答案

您是否应该在设置文件中定义 FIXTURE_DIRS,以便 Django 找到您的灯具。

settings.py

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

Reference

关于DJANGO 1.11 - 找不到固定装置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54510283/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com