我有一个Django项目,我想将测试数据添加到数据库中。当我像这样生成syncdb时
python ~/django/foo/manage.py syncdb
安装表后我遇到了错误
Problem installing fixture '~/django/foo/shop/fixtures/initial_data.json':
Traceback (most recent call last):
raise JSONDecodeError("No JSON object could be decoded", s, idx)
JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)
我的模特在这里:
# -*- coding: utf-8 -*-
from django.db import models
class Image(models.Model):
file = models.ImageField(upload_to = "img/")
title = models.CharField(
max_length=128,
blank = True
)
slug = models.SlugField(max_length=128, blank = True)
def __unicode__(self):
return unicode(self.title)
我的夹具是:
[
{
"pk": 2,
"model": "shop.image",
"fields": {
"slug": "",
"file": "img/8_m.jpg",
"title": "1"
}
}
]
问题出在哪里?
答案 0 :(得分:8)
疯狂猜测...也许您的灯具文件保存为unicode文件???尝试在最简单的文本编辑器中打开它,或运行
hexdump ~/django/foo/shop/fixtures/initial_data.json
并确保转储中的第一个字符为5b
而非fe
或其他内容。