Django 0.96 seems to have a bug when serializing from MySQL. BooleanFields are encoding as 0/1 instead of true/false. Hacking the python serializer seems to fix that.
The bug shows up as (fx. when using loaddata on a dump from MySQL in PostgreSQL):
Problem installing fixture '/tmp/data.json': ERROR: column "is_staff" is of
type boolean but expression is of type integer
HINT: You will need to rewrite or cast the expression.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # In django/core/serializers/python.py add these two lines to the handle_field method:
if isinstance(field, models.BooleanField) and isinstance(self._current[field.name], int):
self._current[field.name] = bool(self._current[field.name])
# Original method
def handle_field(self, obj, field):
self._current[field.name] = getattr(obj, field.name)
# Modified method
def handle_field(self, obj, field):
self._current[field.name] = getattr(obj, field.name)
if isinstance(field, models.BooleanField) and isinstance(self._current[field.name], int):
self._current[field.name] = bool(self._current[field.name])
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 3 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.