BIT(1) Boolean Fields¶
Some database systems, such as the Java Hibernate ORM, don’t use MySQL’s
bool data type for storing boolean flags and instead use BIT(1).
Django’s default BooleanField and NullBooleanField classes can’t work
with this.
The following subclasses are boolean fields that work with BIT(1) columns
that will help when connecting to a legacy database. If you are using
inspectdb to generate models from the database, use these to replace the
TextField output for your BIT(1) columns.
- class Bit1BooleanField¶
A subclass of Django’s
BooleanFieldthat uses theBIT(1)column type instead ofbool.
- class NullBit1BooleanField¶
Note
Django deprecated
NullBooleanFieldin version 3.1 and retains it only for use in old migrations.NullBit1BooleanFieldis similarly deprecated.A subclass of Django’s
NullBooleanFieldthat uses theBIT(1)column type instead ofbool.