0
votes

ubuntu 15.10 venv python 3.4 / django 1.9

command:

python manage.py loaddata flight_data.json(yaml)

errors:

json: django.core.serializers.base.DeserializationError: Problem installing fixture '/home/nerdbox2/django_/logbook/flights/fixtures/flight_data.json': 'model'

yaml: django.core.serializers.base.DeserializationError: Problem installing fixture '/home/nerdbox2/django_/logbook/flights/fixtures/flight_data.yaml': 'model'

After trying several csv->model packages and no luck, I decided to use an online converter for both csv-json and csv-yaml per the Django Docs and still no luck. I have ~2100 records to fill the db with.

yeah, I'm a noob but I really have been beating this to death for the past 3 days!

Any help would be appreciated!

model, json and yaml in comment below

2
can you show us the model and the content of json you are trying to load? - yedpodtrzitko
json 1 of ~2100 original file has trailing bracket: pastebin.com/1ewEDF8S yaml: pastebin.com/ppfDsKTx django model: pastebin.com/832EnXew - user2498975
Hm. Have you tried to read the documentation for loaddata during these three days? Because you would find out, that loaddata can only load fixtures produced by command dumpdata, but your data have different format. Try to dump something via dumpdata to see how the data should look like and edit your fixtures accordingly, or create a custom command for loading the format of data you have. - yedpodtrzitko
Yeah, I did read it, the 1 page there is. The fact that loaddata only works with data produced by dumpdata wasn't clear to me. I've also tried several apps/packages to import the CSV data. It just seems like there would be an "easier" way. Thanks for the reply! - user2498975

2 Answers

2
votes

Sometimes, certain models in an app might be causing the serialization to fail.Django will indicate such models as warnings once you run the dumpdata command. Make sure you exclude such models(or the entire app in certain cases) with the following command :

./manage.py dumpdata --exclude auth.permission > db.json

Here, we consider that auth.permission is the table you need to drop.

If you use a database dump to load the fresh database(in another django project), it can cause IntegrityError (If you loaddata in same database it works fine)

To fix this problem, make sure to backup the database by excluding contenttypes and auth.permissions tables:

./manage.py dumpdata --exclude auth.permission --exclude contenttypes > db.json

Now you can use loaddata command with a fresh database

./manage.py loaddata db.json

Source: https://coderwall.com/p/mvsoyg/django-dumpdata-and-loaddata

0
votes

If you have dump the database excluding permission and content type you have 3 main things to checkout:

1# See your dump json either it is proper key and value accordingly to django serialization, for example:

[

      {

      "model": "myDev.person",

      "pk": 1,

      "fields": {

              "first_name": "anjan",

              "last_name": "thakuri"

      }

    },

     {

      "model": "myDev.person",

      "pk": 2,

      "fields": {

              "first_name": "Swikriti",

              "last_name": "Thakuri"

     }

    }

]

Make sure you have a format like this, which includes 3 keys: pk, model,and fields (rest of the things are inside it).

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

2# If you are using natural key common exceptions that I have faced is because of natural key.

You most know about natural key

3# Same migration instance (phase) for quick guide Stackoverflow