python - Django 1.8 错误 : No database fixture specified

标签 python django postgresql django-database

我使用的是 sqlite 数据库,在应用 python manage.py dumpdata 之后,我在 settings 中添加了新的 postgresql 数据库设置.py

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'music',                      
    'USER': '**',
    'PASSWORD': '****',
    'HOST': '127.0.0.1',
    'PORT': '5432',
    }
  }

但是当我尝试将数据加载到新的 postgresql 数据库中时,出现以下错误

C:\Users\Saket\musicalguru>python manage.py loaddata
usage: manage.py loaddata [-h] [--version] [-v {0,1,2,3}]
                      [--settings SETTINGS] [--pythonpath PYTHONPATH]
                      [--traceback] [--no-color] [--database DATABASE]
                      [--app APP_LABEL] [--ignorenonexistent]
                      fixture [fixture ...]
manage.py loaddata: error: No database fixture specified. Please provide the  path of at least one fixture in the command line.

无法理解错误是什么。我的 sqlite 数据库中已有数据,因此我还需要 postgresql 数据库中的新数据。

最佳答案

你能展示一下你是如何进行数据转储的吗?如果您查看 dumpdata docs ,你会看到它:

Outputs to standard output all data in the database associated with the named application(s).

和:

By default, dumpdata will format its output in JSON

现在,如果您查看错误,您会发现缺少数据库固定装置。 loaddata docs告诉固定装置是什么以及 Django 将在哪里寻找固定装置:

A fixture is a collection of files that contain the serialized contents of the database. Each fixture has a unique name, and the files that comprise the fixture can be distributed over multiple directories, in multiple applications.

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

因此,可以使用将数据转储到的文件:

./manage.py dumpdata ... > mydata.json
./manage.py loaddata mydata.json

关于python - Django 1.8 错误 : No database fixture specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30968970/

相关文章:

python - 如何使用键盘获取 tkinter treeview 选定的行值?

python - 反转字符串并删除第一个字符

python - 提交时刷新表单 - Django

python - django admin 内联编辑外键

django.db.utils.OperationalError : FATAL: role "django" does not exist

sql - 使用 postgresql,如何获得反射(reflect)重叠时间段的日期值

python - 尽管重新绑定(bind) Python.File,Windows 仍使用 C :\Python27\Python. exe 打开 .py 文件

python - 如何在python 2.7中将eigenvector_centrality的结果导出为networkx的csv文件?

python - 在 dehydrate 中序列化查询集

database - 如何处理 PostgreSQL 中大表之间的联接?