I am using dumpdata with Django 1.2.3 on the following model:
class Bar(models.Model):
...
class Foo(models.Model):
bars = models.ManyToManyField(Bar, through="Foo_bar", blank=True, null=True)
...
class Foo_bar(models.Model):
foo = models.ForeignKey(Foo)
bar = models.ForeignKey(Bar)
status = models.IntegerField()
...
The json fixture serializes the bars associated with Foos in the Foo objects, resulting in an AttributeError when I try to run loaddata with the fixture:
AttributeError: Cannot set values on a ManyToManyField which specifies an intermediary model. Use App.Foo_bar's Manager instead.
Based on what I've read, dumpdata may have been fixed to not serialize m2m, or loaddata fixed to properly deal with them, but it doesn't seem so. I've tried the --natural flag, still no luck. Any ideas?
Thanks in advance.
Depending on what you need to do with your fixtures, the command "dumpscript" from the django_extension package is really useful for handling fixture with complex relations.
No primary keys are used in the file, it's just a python script which only uses objects, and as such can re-create your whole db simply using
object.save()
calls.