In a Django application, I am trying to access an existing MySQL database created using Hibernate (Java ORM). I redid the model with:
$ manage.py inspectdb > models.py
This created a good model file from the database, and many things were fine. But I can’t find how to correctly access the logical fields that were displayed by Hibernate as columns of type BIT (1).
The script inspector creates these fields in the model as TextField by default and adds a comment saying that it cannot reliably get the field type. I changed them to BooleanField, but I opened my model objects with the administrator, but it doesn’t work (model objects always get true for these fields). Using IntegerField will also not work (for example, in admin these fields display strange characters other than ascii).
Any hints on this without changing the database? (I need the existing Hibernate mappings and the Java application to continue to work with the database).
Additional information: I left these fields as a BooleanField and used an interactive shell to view the values obtained. They are returned as "\ x00" (when the Java / Hibernate value is false) and "\ x01" (when true), instead of the Boolean Python values "True" and "False".
>>> u = AppUser.objects.all()[0] >>> u.account_expired '\x00' >>> u.account_enabled '\x01'
If the model includes:
class AppUser(models.Model): account_expired = models.BooleanField() account_enabled = models.BooleanField(blank=True)
django mysql orm
Carles barrobés
source share