Пав*_*вин 2 django django-admin django-fixtures
我有一个Django项目,我想将测试数据添加到数据库.当我像这样制作syncdb时
python ~/django/foo/manage.py syncdb
Run Code Online (Sandbox Code Playgroud)
安装表后我遇到了错误
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)
Run Code Online (Sandbox Code Playgroud)
我的模特在这里:
# -*- 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)
Run Code Online (Sandbox Code Playgroud)
我的夹具是这样的:
[
{
"pk": 2,
"model": "shop.image",
"fields": {
"slug": "",
"file": "img/8_m.jpg",
"title": "1"
}
}
]
Run Code Online (Sandbox Code Playgroud)
问题出在哪儿?
疯狂的猜测......也许你的夹具文件被保存为unicode文件??? 尝试在最简单的文本编辑器中打开它,或运行
hexdump ~/django/foo/shop/fixtures/initial_data.json
Run Code Online (Sandbox Code Playgroud)
并确保转储中的第一个字符5b不是fe或什么的.
| 归档时间: |
|
| 查看次数: |
4023 次 |
| 最近记录: |