Re: [Django] #36101: Support BIT data type model field for MySQL and PostgreSQL (was: Support bit data type model field on MySQL, PostgreSQL)

3 views
Skip to first unread message

Django

unread,
Jan 15, 2025, 10:02:32 AM1/15/25
to django-...@googlegroups.com
#36101: Support BIT data type model field for MySQL and PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Jordan Bae | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jordan Bae):

* summary: Support bit data type model field on MySQL, PostgreSQL =>
Support BIT data type model field for MySQL and PostgreSQL


Old description:

> Currently Django model field doesn't support bit data type.
>
> I think It can be helpful to handle bit data type on MySQL, PostgreSQL.
>
> Especially I have below experience.
>
> When I was trying to make a read-only model with inspectdb, bit data type
> column was made by TextField with `This field type is a guess.`.
>
> It's not a bug. but BitField will makes efficiency bit data type and
> other experiences on Django

New description:

Support BIT data type model field for MySQL and PostgreSQL

Currently, Django's model fields do not support the BIT data type which is
available in both MySQL and PostgreSQL databases.

Key reasons for adding BIT data type support:

1. Improved Database Inspection
- When using `inspectdb` on tables containing BIT columns, Django
currently falls back to TextField with a "This field type is a guess"
comment
- Native BitField support would provide accurate model generation for
existing databases

2. Database-specific Features
- MySQL: Support for BIT(M) where M can specify the number of bits
- PostgreSQL: Support for both BIT(n) and BIT VARYING(n) types

3. Use Cases
- Efficient storage of boolean flags and bit flags
- Direct mapping to database-native bit operations
- Better integration with legacy databases using BIT columns

This enhancement would improve Django's database type coverage and provide
more efficient handling of bit-based data.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36101#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages