﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14094	Cannot define CharField with unlimited length	Daniel Miller	Adrian Torres	"Model validation throws an error on CharField with a null max_length:


{{{
#!python
class Test(Model):
    char_field = CharField(max_length=None)
}}}


'''
One or more models did not validate:[[BR]]
test.test: ""char_field"": CharFields require a ""max_length"" attribute that is a positive integer.
'''


CharField should allow max_length=None, which intuitively means there is no maximum length. This is a perfectly valid use case. Postgres, for example, supports varchar/text columns without a length limit, but Django appears to have no way to define such a column in a model class.


The model validation code looks like this ([http://code.djangoproject.com/browser/django/tags/releases/1.2.1/django/core/management/validation.py#L40 django/core/management/validation.py:40]):



{{{
#!python
    if isinstance(f, models.CharField):
        try:
            max_length = int(f.max_length)
            if max_length <= 0:
                e.add(opts, '""%s"": CharFields require a ""max_length"" attribute that is a positive integer.' % f.name)
        except (ValueError, TypeError):
            e.add(opts, '""%s"": CharFields require a ""max_length"" attribute that is a positive integer.' % f.name)
}}}


It should be changed to something this:


{{{
#!python
    if isinstance(f, models.CharField) and f.max_length is not None:
        ...
}}}


The FileField does not happen to throw this error because it is not a derivative of CharField. However, the SQL generated for FileField is not correct when max_length=None, so that would need to be addressed as well."	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed		joe@… mightyiam unai@… Aron Podrigal Rich Rauenzahn Anvesh Mishra Adrian Torres	Ready for checkin	1	0	0	0	0	0
