我有两组固定装置,Person.json 和 Movies.json。Person 夹具基本上有这种格式:
{
"pk": 1,
"model": "data.Person",
"fields": {
"full": "Anna-Varney",
"num": "I",
"short": "Anna-Varney"
}
},
我先加载它,没问题。我的 movie.json 看起来像这样:
{
"pk": 1,
"model": "data.Film",
"fields": {
"date": "2005-08-01",
"rating": 8.3,
"actors": [
[
"Anna-Varney"
]
],
"name": "Like a Corpse Standing in Desperation (2005) (V)"
}
},
并加载电影夹具给我这个错误:
DeserializationError: Problem installing fixture 'data/fixtures/movies.json': Person matching query does not exist.
我的模型是:
class PersonManager(models.Manager):
def get_by_natural_key(self, full):
return self.get(full=full)
class Person(models.Model):
objects = PersonManager()
full = models.CharField(max_length=100,unique = True)
short = models.CharField(max_length=100)
num = models.CharField(max_length=5)
def natural_key(self):
return (self.full,)
def __unicode__(self):
return self.full
class Film(models.Model):
name = models.TextField()
date = models.DateField()
rating = models.DecimalField(max_digits=3 , decimal_places=1)
actors = models.ManyToManyField('Person')
def __unicode__(self):
return self.name
我过去加载了类似的模型和固定装置,但我正在尝试重构我的一些代码,所以现在它不起作用。我所做的显着更改之一是我使用的是 PostgreSQL 而不是 MySQL,并且我在 virtualenv 中运行所有东西。有没有办法查明错误发生在夹具的哪个位置?