2

我有一个 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"
        }
    }
]

哪里有问题?

4

1 回答 1

8

疯狂的猜测......也许你的夹具文件被保存为一个unicode文件???尝试在最简单的文本编辑器中打开它,或者运行

hexdump ~/django/foo/shop/fixtures/initial_data.json

并确保转储中的第一个字符5b不是fe什么的。

于 2012-01-04T19:43:36.113 回答