Django 1.8 error: No database fixture specified

12.9k views Asked by At

I was using an sqlite database and after applying python manage.py dumpdata I added the new postgresql database settings in settings.py

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

But when I try to load the data into the new postgresql database I get the following error

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.

Can't understand what the error is. I already have data in my sqlite database so I need the new data in the postgresql database too.

2

There are 2 answers

2
Mike Covington On BEST ANSWER

Can you show how you did the data dump? If you look at the dumpdata docs, you'll see that it:

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

And:

By default, dumpdata will format its output in JSON

Now, if you take a look at your error, you'll see that you are missing a database fixture. The loaddata docs tells what a fixture is and where Django will look for fixtures:

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

So, the file that you dump your data to can be used:

./manage.py dumpdata ... > mydata.json
./manage.py loaddata mydata.json
0
Aamir Rind On

You need to tell loaddata which file to load if it is not in app fixtures directory:

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

Either you move your dumped data in fixtures directory of app or specify file manually as I stated above. Read move about loaddata command here.