Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#34887 closed New feature (wontfix)

Allow unlimited CharField for SQLite backend

Reported by: Kar Petrosyan Owned by: Kar Petrosyan
Component: Database layer (models, ORM) Version: 4.2
Severity: Normal Keywords: SQLite
Cc: Triage Stage: Unreviewed
Has patch: no 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 (4)

comment:1 by Kar Petrosyan, 8 months ago

Owner: changed from nobody to Kar Petrosyan

comment:2 by Mariusz Felisiak, 8 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, 8 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, 8 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.

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