Opened 14 months ago
Closed 14 months ago
#35759 closed New feature (duplicate)
Don't require max_length on CharField on SQLite backend
| Reported by: | Curtis Maloney | Owned by: | Jae Hyuck Sa |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 5.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
Some trivial testing suggests that SQLite doesn't require a length on VARCHAR / TEXT fields, just like Postgres.
Change History (9)
comment:1 by , 14 months ago
comment:2 by , 14 months ago
| Triage Stage: | Unreviewed → Accepted |
|---|
SQLite doesn't enforce any database constraints when a max length is specified (see #21471 and this recent forum discussion on the subject) so supporting max_length=None on SQLite is trivial (we already implicitly do).
For anyone interested in picking this up the patch needs three things
- The SQLite backend's
supports_unlimited_charfieldfeature flag must be set to true. - The
CharFielddocumentation must be adjusted to mention the feature is available of SQLite as well with a::versionchanged. - A release note must be added.
comment:3 by , 14 months ago
I’ve always been interested in Database/ORM, so I’d like to handle this ticket myself. Thank you, Simon Charette, for providing such detailed guidelines.
comment:4 by , 14 months ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:5 by , 14 months ago
| Has patch: | set |
|---|
follow-up: 7 comment:6 by , 14 months ago
Patch is looking great.
For the record #34887 initially rejected this feature but I think it warrants being revisited. The argument provided by Mariusz at the time was
We accepted #14094, because CharField and TextField use different datatypes on PostgreSQL.
but in the end both varchar and text are aliases for the internal Postgres varlena type so I don't think the argument stands. There are reason why we'd want to allow CharField(max_length=None) on all backends that allow it which #14094 does a good job at covering.
Moreover the addition of this feature could allow us to eventually automatically add a check constraint for max_length on SQLite by allowing users to disable it entirely by setting the value to None.
comment:7 by , 14 months ago
Replying to Simon Charette:
Patch is looking great.
For the record #34887 initially rejected this feature but I think it warrants being revisited. The argument provided by Mariusz at the time was
We accepted #14094, because CharField and TextField use different datatypes on PostgreSQL.
but in the end both
varcharandtextare aliases for the internal Postgresvarlenatype so I don't think the argument stands. There are reason why we'd want to allowCharField(max_length=None)on all backends that allow it which #14094 does a good job at covering.
Moreover the addition of this feature could allow us to eventually automatically add a check constraint for
max_lengthon SQLite by allowing users to disable it entirely by setting the value toNone.
Thank you for the detailed explanation! :)
It would vastly simplify my own package testing if I didn't have to spin up a PG instance for models written assuming I can omit
max_length, and could instead use a disposable SQLite DB.