#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
inspectdbon 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 (3)
comment:1 by , 10 months 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 , 10 months ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
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
BinaryFieldwhich I don't see mentioned in your report implemented aslongblobon MySQL andbyteaon Postgres which should cover most of the usage aBitFieldwould have.This argument could stand for pretty much any type that database support and Django doesn't have a field equivalent for.
Apparently
byteais more space efficient thanbit varyingon PostgreSQL so if you've reached a point where the storage of boolean bits and flags is of a concernBinaryFieldwould 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
BinaryFieldas well.Given that you can likely implement a
BitFieldby subclassingBinaryField, overriding it'sdb_typemethod to returnf"bit({self.max_length})"and that adding aBitFieldin core while there are third-party alternatives would incur a significant maintenance burden I'm 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.