Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango ORM dealing with MySQL BIT(1) field
    primarykey
    data
    text
    <p>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:</p> <pre><code>$ manage.py inspectdb &gt; models.py </code></pre> <p>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).</p> <p>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 and opened my model objects using the admin, 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).</p> <p>Any hints of doing this without changing the database? (I need the existing Hibernate mappings and Java application to still work with the database).</p> <hr> <p>Further info: I left these fields as BooleanField and used the interactive shell to look at the fetched values. They are returned as '\x00' (when Java/Hibernate value is false) and '\x01' (when true), instead of Python boolean values "True" and "False".</p> <pre><code>&gt;&gt;&gt; u = AppUser.objects.all()[0] &gt;&gt;&gt; u.account_expired '\x00' &gt;&gt;&gt; u.account_enabled '\x01' </code></pre> <p>Where the model includes:</p> <pre><code>class AppUser(models.Model): account_expired = models.BooleanField() account_enabled = models.BooleanField(blank=True) # etc... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload