Django 1.8 error: No database fixture specified

Django 1.8 error: No database fixture specified

我使用的是 sqlite 数据库,在应用 python manage.py dumpdata 之后,我在 settings.py

中添加了新的 postgresql 数据库设置
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 数据库中的新数据。

你需要告诉 loaddata 如果哪个文件不在应用程序 fixtures 目录中,则加载哪个文件:

python manage.py loaddata file/path/of/dumbdata.json

要么将转储的数据移动到应用程序的 fixtures 目录中,要么如上所述手动指定文件。阅读关于 loaddata 命令的移动 here.

你能展示一下你是如何进行数据转储的吗?如果您查看 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