Opened 15 months ago
Closed 3 months ago
#34887 closed New feature (fixed)
Allow unlimited CharField for SQLite backend
Reported by: | Kar Petrosyan | Owned by: | Jae Hyuck Sa |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 4.2 |
Severity: | Normal | Keywords: | SQLite |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Model validation throws an error on CharField when the max_length argument is not specified.
class MyModel(models.Model): name = models.CharField()
The developer who knows that SQLite can store unlimited characters would be surprised in such cases.
I suggest allowing unlimited characters for SQLite, like we do for PostgreSQL.
Relevant PostgreSQL ticket: https://code.djangoproject.com/ticket/14094
Change History (9)
comment:1 by , 15 months ago
Owner: | changed from | to
---|
follow-up: 3 comment:2 by , 15 months ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Resolution: | → wontfix |
Status: | assigned → closed |
follow-up: 4 comment:3 by , 15 months ago
Replying to Mariusz Felisiak:
SQLite has limited number of datatypes, and there is no difference between
TEXT
andVARCHAR
(no declared max length), both would be stored in theTEXT
datatype. You can useTextField
for unlimitedCharField
.
Does it really solve the problem? I want to use CharField and not TextField (when using sqlite3 for the startup but planning to migrate to another DBMS).
In such cases, I can use CharField (max_length = 1), but it wouldn't make any sense for the reviewer.
comment:4 by , 15 months ago
Replying to karosis88:
Does it really solve the problem?
Yes.
I want to use CharField and not TextField (when using sqlite3 for the startup but planning to migrate to another DBMS).
In such cases, I can use CharField (max_length = 1), but it wouldn't make any sense for the reviewer.
There is no way to switch between databases without changing anything. It's recommended to use the same database in development and production environments, unless you're aware of all migration caveats. We accepted #14094, because CharField
and TextField
use different datatypes on PostgreSQL.
comment:5 by , 3 months ago
For the record I've opted into accepting this feature in ticket:35759#comment:6 as to me the situation on SQLite is similar to Postgres.
On SQLite both varchar
and text
are an alias for the same internal type but it's also the case on Postgres where they are aliases for varlena
.
The lack of constraint enforcement on SQLite is a distinct problem (see #21471) that allowing max_length=None
could help solving by providing a way to restore the previous behaviour for users that need it.
comment:6 by , 3 months ago
Has patch: | set |
---|---|
Resolution: | wontfix |
Status: | closed → new |
Triage Stage: | Unreviewed → Accepted |
#35759 was a duplicate - reopening and accepting
comment:8 by , 3 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
SQLite has limited number of datatypes, and there is no difference between
TEXT
andVARCHAR
(no declared max length), both would be stored in theTEXT
datatype. You can useTextField
for unlimitedCharField
.