Django 1.9 loaddata错误 [英] Django 1.9 loaddata errors

查看:39
本文介绍了Django 1.9 loaddata错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ubuntu 15.10venv python 3.4/django 1.9

ubuntu 15.10 venv python 3.4 / django 1.9

命令:

python manage.py loaddata flight_data.json(yaml)

错误:

json:django.core.serializers.base.DeserializationError:问题安装夹具'/home/nerdbox2/django_/logbook/flights/fixtures/flight_data.json':'模型'

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:问题安装夹具'/home/nerdbox2/django_/logbook/flights/fixtures/flight_data.yaml':'模型'

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

在尝试了多个csv-> model包并且没有运气之后,我决定根据Django Docs对csv-json和csv-yaml使用在线转换器,但仍然没有运气.我有大约2100条记录可以填充数据库.

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.

是的,我是菜鸟,但在过去3天里,我确实一直将其击败!

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

任何帮助将不胜感激!

模型,json和yaml在下面的评论中

model, json and yaml in comment below

推荐答案

有时,应用程序中的某些模型可能会导致序列化失败.一旦运行dumpdata命令,Django就会将这些模型指示为警告.确保使用以下命令排除此类模型(在某些情况下为整个应用程序):

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

在这里,我们认为auth.permission是您需要删除的表.

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

如果您使用数据库转储来加载新的数据库(在另一个django项目中),则可能导致IntegrityError(如果您在同一数据库中加载数据,则可以正常工作)

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)

要解决此问题,请确保通过排除内容类型和auth.permissions表来备份数据库:

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

现在您可以对新的数据库使用loaddata命令

Now you can use loaddata command with a fresh database

./manage.py loaddata db.json

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

这篇关于Django 1.9 loaddata错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆