Opened 4 years ago

Closed 4 years ago

#21471 closed Bug (invalid)

CharField max_lenght is not enforced on SQLite backend with Python 3

Reported by: lvella Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I am using Django 1.6 with CPython 3.3.2. The minimal test case to show the bug is as follows:

From a Django project using SQLite, create an app:

$ python3 startapp case

Add the following contents to 'case/':

from django.db import models

class A(models.Model):

b = models.CharField(max_length=10)

def str(self):

return self.b

Then, after adding the app to INSTALLED_APPS setting, sync the database:

$ python3 syncdb

Then run:
$ python3 shell

from case.models import A
a = A(b='x'*20)

<A: xxxxxxxxxxxxxxxxxxxx>

If you could reproduce, the 20 characters string was allowed on a CharField with max_length=10. This caused me problems because I user SQLite on development, and PostgreSQL on production, and because of this issue, I missed a bug during development only to see it in production.

Change History (1)

comment:1 Changed 4 years ago by Tim Graham

Resolution: invalid
Status: newclosed

Yes, this is a limitation of SQLite. see

This is why it's recommended to use the same database for development as you use in production.

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