简体   繁体   中英

Django 1.9 loaddata errors

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

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

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 guideStackoverflow

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM