加载django fixtures时出错

时间:2013-10-09 18:49:14

标签: django django-models django-fixtures

我有两套灯具,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中运行一切。 有没有办法确定错误发生在灯具中的哪个位置?

0 个答案:

没有答案