Opened 9 years ago

Closed 9 years ago

#24939 closed Uncategorized (invalid)

min_length not working for charField

Reported by: Brandon Osborn Owned by: nobody
Component: Forms Version: 1.8
Severity: Normal Keywords: charField, min_length
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes


This code:

class SignUp(models.Model):
	email = models.EmailField()
	first_name = models.CharField(max_length=50, blank=False,   null=False)
	last_name = models.CharField(max_length=50, blank=False, null=False)
	timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
	updated = models.DateTimeField(auto_now_add=False, auto_now=True)

	def __str__(self):

Works fine, but if I change one of the Charfields to:

        last_name = models.CharField(min_length=2, max_length=50, blank=False, null=False)


        last_name = models.CharField(max_length=50, min_length=2, blank=False, null=False)


        last_name = models.CharField(min_length=2, blank=False, null=False)

the server aborts, with the following error, which refers to the file:

TypeError:  __init()__ got an unexpected keyword argument 'min_length'

The charField documentation at:
Validates max_length or min_length, if they are provided. Otherwise, all inputs are valid

Change History (1)

comment:1 by Simon Charette, 9 years ago

Resolution: invalid
Status: newclosed

Hi bjosborn,

It looks like you are mixing up form fields and model fields. The min_length option is available for forms.CharField but not for models.CharField.

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