Getting a DeserializationError when trying to load data from JSON to DB

I have this JSON file called data.json which is saved in my /fixtures folder. I cannot load my data into a model as I enter python loaddata data.json, I get this error.

I have made sure the file is in the proper JSON format but I can’t figure out what is causing this error.

Traceback (most recent call last):
File "/home/msd/.local/lib/python3.6/site-packages/django/core/serializers/", line 69, in    Deserializer
yield from PythonDeserializer(objects, **options)
File "/home/msd/.local/lib/python3.6/site-packages/django/core/serializers/", line 91, in Deserializer
Model = _get_model(d["model"])
KeyError: 'model'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "", line 21, in <module>
File "", line 17, in main
File "/home/msd/.local/lib/python3.6/site-packages/django/core/management/", line 401, in    execute_from_command_line
File "/home/msd/.local/lib/python3.6/site-packages/django/core/management/", line 395, in execute
File "/home/msd/.local/lib/python3.6/site-packages/django/core/management/", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/msd/.local/lib/python3.6/site-packages/django/core/management/", line 369, in execute
output = self.handle(*args, **options)
File "/home/msd/.local/lib/python3.6/site-packages/django/core/management/commands/", line 72, in handle
File "/home/msd/.local/lib/python3.6/site-packages/django/core/management/commands/", line 114, in loaddata
File "/home/msd/.local/lib/python3.6/site-packages/django/core/management/commands/", line 172, in load_label
for obj in objects:
File "/home/msd/.local/lib/python3.6/site-packages/django/core/serializers/", line 73, in Deserializer
raise DeserializationError() from exc
django.core.serializers.base.DeserializationError: Problem installing fixture '/home/msd/Projects/Django/markets/fixtures/data.json':

Your file is not in the proper format to be loaded as a JSON fixture within Django using loaddata.

See the sample for providing data with fixtures.

Hi Ken,

Specifically, for a JSON fixture to be loaded does my file require the model , pk and field keys?


Generally speaking, yes. There’s a link in that page that points you to the JSON Serialization format, which provides a more formal and complete specification.

(The most common exception that I deal with is that the requirements are slightly different if you are using Natural Keys.)


hi KenWhitesell, I used the dumpdata argument of to create the JSON file I didn’t create it manually so but still, I am getting this error. Does that mean the dumpdata will not create the file as required for loading the fixtures and I will have to create it manually?

No, dumpdata works perfectly for creating files usable by loaddata.

There are a couple different reasons why it might fail - the most common reasons I’ve seen are either foreign key relationships not being properly maintained or natural keys not being used (or not being used correctly).

For example, if you’ve got Model X that has a ForeignKey field to Model Y. Then Model Y must be loaded before Model X.

If you’re having a specific issue loading a file, it might be helpful if you post the complete traceback message you’re getting, the model you’re trying to load, and perhaps the first two or three rows being loaded from the JSON file.