1

I have two sets of fixtures, Person.json and Movies.json. The Person fixture basically have this format:

  {
    "pk": 1,
    "model": "data.Person",
    "fields": {
      "full": "Anna-Varney",
      "num": "I",
      "short": "Anna-Varney"
    }
  },

And I load it in first, and it's fine no problem. My movie.json looks like this:

  {
    "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)"
    }
  },

And loading the movies fixture in gives me this error:

DeserializationError: Problem installing fixture 'data/fixtures/movies.json': Person matching query does not exist.

My models are:

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

I've loaded in similar models and fixtures in the past that worked, but I'm trying to refactor a bit of my code so now it doesn't work. One of the notable changes I've made was that I'm PostgreSQL instead of MySQL and that I'm running everything in virtualenv. Is there a way to pinpoint where in the fixture that the error occurs?

dl8
  • 1,270
  • 1
  • 14
  • 34
  • I'm not too familiar with creating natural keys when dumping the data, but why is the `actors` key in the `movie.json` a nested list? Shouldn't it be a single list. Maybe try returning just the fullname (instead of the tuple) in your `natural_key` function on `Person` – Timmy O'Mahony Oct 09 '13 at 19:02
  • Because the movie holds a list of all the actors that have played in it. And it has to be a tuple for it to be valid (even stated in documentation) – dl8 Oct 09 '13 at 19:06
  • I think I located the problem. In the past when I used MySQL I omitted duplicate names that have different cases when creating the fixtures since I would get errors about duplicate entries, but I just read that PostGres is case-sensitive for string comparisons. So I'll try fixing that for now. – dl8 Oct 09 '13 at 19:13
  • I had the same issue, but I wasn't using proper JSON (python instead) E.g. *None* should be *null*. No commas allowed after the last element of a list, *False* must be *false*. – kev Nov 03 '14 at 00:33

0 Answers0