Saturday, March 22, 2014

loaddata not looking for natural keys

loaddata error message:
File "/home/bob/.virtualenvs/vn2/lib/python2.6/site-packages/django/core/serializers/json.py", line 47, in Deserializer
    raise DeserializationError(e)
DeserializationError: [u"'Cash Contribution' value must be an integer."]

Here's how I dumped the data:
./manage.py dumpdata valueaccounting.AgentType  valueaccounting.Facet valueaccounting.FacetValue valueaccounting.ProcessPattern valueaccounting.PatternFacetValue  valueaccounting.Project --natural --indent=4 > starters.json

Then I did syncdb and migrate.

Then I tried loaddata:
./manage.py loaddata starters.json

Here's the offending json:

    {
        "pk": 22, 
        "model": "valueaccounting.patternfacetvalue", 
        "fields": {
            "facet_value": 4, 
            "pattern": 9, 
            "event_type": "Cash Contribution"
        }
    }, 

Here's the relevant natural key code:

class EventTypeManager(models.Manager):

    def get_by_natural_key(self, name):
        return self.get(name=name)

class EventType(models.Model):
[...]
    objects = EventTypeManager()

    def natural_key(self):
        return (self.name)

So what am I missing?  (I put a pdb trace in the get_by_natural_key method, never got called.) 

I am stumped. But I expect it is some stupid mistake that I can't see...

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4023a879-c7e5-458e-8235-72a517102572%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment