2

I've a Django project and I want to add test data to database. When I make syncdb like this

python ~/django/foo/manage.py syncdb

After tables are installed I've got an error

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)

My model is here:

# -*- 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)

My fixture is this:

[
    {
        "pk": 2, 
        "model": "shop.image", 
        "fields": {
            "slug": "", 
            "file": "img/8_m.jpg", 
            "title": "1"
        }
    }
]

Where is the problem?

Павел Тявин
  • 2,529
  • 4
  • 25
  • 32

1 Answers1

8

Wild guess... maybe your fixture file is saved as a unicode file??? Try to open it in the simplest text editor you can, or run

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

and make sure the first character in the dump is 5b not fe or something.

Leopd
  • 41,333
  • 31
  • 129
  • 167
  • I'm getting the same error and this seems to be the problem. Now what can I do about it? Thanks for your help in advance. – Ryan R. Apr 02 '12 at 13:27
  • One simple way is `cat > ascii_fixture.json` and then copy/paste the file's contents and then control-D to finish it. For huge files or windows google "convert unicode text file to ascii". – Leopd Aug 16 '12 at 16:52