I have serialized 4 apps from my project with manage.py dumpdata. But when I’m trying to load it in test as a fixture – i’m getting “Validation Error : This value must be True or False”.
How to understand, which line of dump is wrong? Or in which model I got this error?
UPD:
Problem is coming from invalid fixture. But I can’t understand, why django dumbdata creates invalid fixtures.
I have added
print field.name
in django.core.serializers.python and found invalid values manually. But it’s not good way.
UPD.
I’m still interested in a way to dump data for any model and reuse it in tests as a fixture. I’m using postgresql for development.
First of all are you using any custom/3rd party Fields?
Although if you did and django’s dumpdata couldn’t serialize it, it
would raise an exception I suppose. Anyway since last time I checked there
was not any sufficient documentation for writing a custom django serializer,
here is an example for serializing a custom UUIDField:
Then in your settting.py add
Then from your shell you can do
You can load it with
Strangely enough
loaddatadoes not accept a “format” parameter like dumpdata. It decides the format based on the file extension. Yet I could not find a way tohook my custom encoder, so I had to write a “new” serializer 🙁
That’s what I did months ago when I needed to write a custom serializer and
I had to dig through the django’s source code to figure it out, since
the official docs had nothing on the subject. I hope it provides some help.