从django中的json文件创建fixture
在Django 2.2中加载夹具时遇到问题 我的fixtures文件夹中有一个名为data.json的文件,如下所示:从django中的json文件创建fixture,django,django-fixtures,Django,Django Fixtures,在Django 2.2中加载夹具时遇到问题 我的fixtures文件夹中有一个名为data.json的文件,如下所示: [{"model": "Headline", "pk": 1, "fields": {"article_link": "https://www.huffingtonpost.com/entry/versace-black-code_us_5861fbefe4b0de3a08f600d5", "headline": "former versace store clerk sues
[{"model": "Headline", "pk": 1, "fields": {"article_link": "https://www.huffingtonpost.com/entry/versace-black-code_us_5861fbefe4b0de3a08f600d5", "headline": "former versace store clerk sues over secret 'black code' for minority shoppers", "is_sarcastic": 0}}, {"model": "Headline", "pk": 2, "fields": {"article_link": "https://www.huffingtonpost.com/entry/roseanne-revival-review_us_5ab3a497e4b054d118e04365", "headline": "the 'roseanne' revival catches up to our thorny political mood, for better and worse", "is_sarcastic": 0}}, {"model": "Headline", "pk": 3, "fields": {"article_link": "https://local.theonion.com/mom-starting-to-fear-son-s-web-series-closest-thing-she-1819576697", "headline": "mom starting to fear son's web series closest thing she will have to grandchild", "is_sarcastic": 1}}]
[
{
"model": "myapp.headline",
"pk": 1,
"fields": {
"article_link": "https://foobar.com",
"headline": "Test",
"is_sarcastic": 1
}
},
{
"model": "myapp.headline",
"pk": 2,
"fields": {
"article_link": "https://foobar.com",
"headline": "Test",
"is_sarcastic": 1
}
}
]
我有这个模型:
from django.db import models
class Headline(models.Model):
article_link = models.CharField(max_length=250)
headline = models.CharField(max_length=500)
is_sarcastic = models.IntegerField()
我一直在犯这个错误,不知道到底出了什么问题
django.core.serializers.base.DeserializationError:
您的固定装置应如下所示:
[{"model": "Headline", "pk": 1, "fields": {"article_link": "https://www.huffingtonpost.com/entry/versace-black-code_us_5861fbefe4b0de3a08f600d5", "headline": "former versace store clerk sues over secret 'black code' for minority shoppers", "is_sarcastic": 0}}, {"model": "Headline", "pk": 2, "fields": {"article_link": "https://www.huffingtonpost.com/entry/roseanne-revival-review_us_5ab3a497e4b054d118e04365", "headline": "the 'roseanne' revival catches up to our thorny political mood, for better and worse", "is_sarcastic": 0}}, {"model": "Headline", "pk": 3, "fields": {"article_link": "https://local.theonion.com/mom-starting-to-fear-son-s-web-series-closest-thing-she-1819576697", "headline": "mom starting to fear son's web series closest thing she will have to grandchild", "is_sarcastic": 1}}]
[
{
"model": "myapp.headline",
"pk": 1,
"fields": {
"article_link": "https://foobar.com",
"headline": "Test",
"is_sarcastic": 1
}
},
{
"model": "myapp.headline",
"pk": 2,
"fields": {
"article_link": "https://foobar.com",
"headline": "Test",
"is_sarcastic": 1
}
}
]
您可以在此处查看:抱歉,我将“模型”:“Headline”更改为“model”:“sarcasm.Headline”(该应用程序称为sarcasm)-仍然不走运?您能在此处发布完整的回溯吗?谢谢您的耐心,我使用在线转换器将json转换为格式良好的json,现在我无法加载sarcasm.Headline(pk=1867):值太长,无法更改类型字符(250)-似乎与我在字符字段上设置的最大长度有多大无关。您的最大长度设置为500,但该值不存在。要么使用最大长度为255的CharField,要么使用没有最大长度的TextField。我确实改为TextField并进行了迁移,但这没有帮助