姜戈装置。 JSON解码错误

发布于 2024-12-24 03:43:21 字数 1027 浏览 1 评论 0原文

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

问题出在哪里?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北座城市 2024-12-31 03:43:21

大胆猜测...也许你的装置文件保存为 unicode 文件???尝试在最简单的文本编辑器中打开它,或者运行

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

并确保转储中的第一个字符是 5b 而不是 fe 或其他字符。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文