2015-06-21 79 views
0

我使用sqlite数据库和应用python manage.py dumpdata后,我在settings.py的Django 1.8错误:没有数据库灯具指定

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

添加了新的postgresql数据库设置但是当我尝试将数据加载到新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数据库中的新数据。

回答

4

你能告诉我你是如何做数据转储的吗?如果你看一下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 
+0

好运行'manage.py dumpdata> mydata.json'创建一个只包含可用的django子命令列表的文件。里面没有数据。并且运行'manage.py loaddata mydata.json'只是在命令行上返回相同的列表。之前运行的'python manage.py dumpdata'至少返回了数据库中所有数据的混乱列表。可能是什么问题? – WutWut

+0

奇怪的是,唯一一次我看到'manage.py'的子命令列表是如果我运行它而不是一个子命令,或者如果我运行它'/ help'。完全按照“工作时”的方式运行,但在后面加入'> mydata.json'。 –

1

你需要告诉loaddata要加载的文件,如果它不是在应用fixtures目录:

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

要么你将你的甩数据fixtures目录应用程序或手动指定的文件,因为我上述。阅读移动约loaddata命令here