Opened 14 months ago

Closed 2 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 Kar Petrosyan, 14 months ago

Owner: changed from nobody to Kar Petrosyan

comment:2 by Mariusz Felisiak, 14 months ago

Component: UncategorizedDatabase layer (models, ORM)
Resolution: wontfix
Status: assignedclosed

SQLite has limited number of datatypes, and there is no difference between TEXT and VARCHAR (no declared max length), both would be stored in the TEXT datatype. You can use TextField for unlimited CharField.

in reply to:  2 ; comment:3 by Kar Petrosyan, 14 months ago

Replying to Mariusz Felisiak:

SQLite has limited number of datatypes, and there is no difference between TEXT and VARCHAR (no declared max length), both would be stored in the TEXT datatype. You can use TextField for unlimited CharField.

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.

in reply to:  3 comment:4 by Mariusz Felisiak, 14 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 Simon Charette, 2 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.

Last edited 2 months ago by Simon Charette (previous) (diff)

comment:6 by Sarah Boyce, 2 months ago

Has patch: set
Resolution: wontfix
Status: closednew
Triage Stage: UnreviewedAccepted

#35759 was a duplicate - reopening and accepting

comment:7 by Sarah Boyce, 2 months ago

Owner: changed from Kar Petrosyan to Jae Hyuck Sa
Status: newassigned

comment:8 by Sarah Boyce, 2 months ago

Triage Stage: AcceptedReady for checkin

comment:9 by Sarah Boyce <42296566+sarahboyce@…>, 2 months ago

Resolution: fixed
Status: assignedclosed

In fd92f24:

Fixed #34887 -- Added support for unlimited models.CharField on SQLite.

Signed-off-by: saJaeHyukc <wogur981208@…>

Note: See TracTickets for help on using tickets.
Back to Top