Django ORM dealing with MySQL BIT(1) field

Posted by Carles Barrobés on Stack Overflow See other posts from Stack Overflow or by Carles Barrobés
Published on 2010-04-24T20:39:34Z Indexed on 2010/04/24 20:43 UTC
Read the original article Hit count: 221

Filed under:
|
|

In a Django application, I'm trying to access an existing MySQL database created with Hibernate (a Java ORM). I reverse engineered the model using:

$ manage.py inspectdb > models.py

This created a nice models file from the Database and many things were quite fine. But I can't find how to properly access boolean fields, which were mapped by Hibernate as columns of type BIT(1).

The inspectdb script by default creates these fields in the model as TextField and adds a comment saying that it couldn't reliably obtain the field type. I changed these to BooleanField but it doesn't work (the model objects always fetch a value of true for these fields). Using IntegerField won't work as well (e.g. in the admin these fields show strange non-ascii characters).

Any hints of doing this without changing the database? (I need the existing Hibernate mappings and Java application to still work with the database).

© Stack Overflow or respective owner

Related posts about django

Related posts about orm