#36101 closed New feature (wontfix)
Support BIT data type model field for MySQL and PostgreSQL
Reported by: | Jordan Bae | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Jordan Bae | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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:
- 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
- When using
- 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
- 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.
Change History (2)
comment:1 by , 6 hours ago
Description: | modified (diff) |
---|---|
Summary: | Support bit data type model field on MySQL, PostgreSQL → Support BIT data type model field for MySQL and PostgreSQL |
comment:2 by , 3 hours ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Version 0, edited 3 hours ago by (next)
Note:
See TracTickets
for help on using tickets.
I'm not convinced that we should add a dedicated field for this given we already have the all purposed
BinaryField
which I don't see mentioned in your report implemented aslongblob
on MySQL andbytea
on Postgres which should cover most of the usage aBitField
would have.This argument could stand for pretty much any type that database support and Django doesn't have a field equivalent for.
Apparently
bytea
is more space efficient thanbit varying
on PostgreSQL so if you've reached a point where the storage of boolean bits and flags is of a concernBinaryField
would be a better option on Postgres at least.These database-native bit operations would need to be implemented as lookups and transforms anyway on the ORM side which is something that could be done with
BinaryField
as well.Given that you can likely implement a
BitField
by subclassingBinaryField
, overriding it'sdb_type
method to returnf"bit({self.max_length})"
and that adding aBitField
in core while there are third-party alternatives I'm would incur a significant maintenance burden going to close this ticket as wontfix.If you disagree please create a forum discussion to try to form community consensus on the subject as documented when proposing new features.