python – Django fixture数据没有有效的模型标识符?
作者:互联网
我确信这里有一个简单的答案,但我看不到它.我正在尝试将fixtures加载到我的数据库中,但无论我使用什么模型标识符,我都会得到DeserializationError:无效的模型标识符:… error.
文件结构:
testproject/
testapp/
fixtures/
data.json
__init__.py
models.py
tests.py
views.py
sqlite3.db
__init__.py
manage.py
settings.py
urls.py
由于这是我第一次参加灯具,我使用http://www.djangoproject.com/documentation/models/fixtures/的模型:
from django.db import models
from django.conf import settings
class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
def __unicode__(self):
return self.headline
class Meta:
ordering = ('-pub_date', 'headline')
data.json:
[
{
"pk": "3",
"model": "testapp.article",
"fields":
{
"headline": "Time to reform copyright",
"pub_date": "2006-06-16 13:00:00"
}
},
{
"pk": "2",
"model": "testapp.article",
"fields":
{
"headline": "Poker has no place on ESPN",
"pub_date": "2006-06-16 12:00:00"
}
},
{
"pk": "1",
"model": "testapp.article",
"fields":
{
"headline": "Python program becomes self aware",
"pub_date": "2006-06-16 11:00:00"
}
}
]
我试过testapp.article,testproject.article,testproject.testapp.article,它们都抛出相同的错误.我使用Python 2.6运行1.2.4并使用loaddata而不是syncdb.有任何想法吗?
解决方法:
你的data.json文件没问题,我已经尝试过它了.
你确定你的数据库与你的模型同步了吗?
你运行什么来加载文件?
正如Luc建议的那样,将“manage.py dumpdata testapp”输出与您的文件进行比较
标签:python,django,fixtures 来源: https://codeday.me/bug/20190705/1382613.html