Opened 5 years ago

Closed 5 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

Description

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):
		return self.email

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)

or

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

or

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

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

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

The charField documentation at:
https://docs.djangoproject.com/en/1.8/ref/forms/fields/#charfield
States:
Validates max_length or min_length, if they are provided. Otherwise, all inputs are valid

Change History (1)

comment:1 Changed 5 years ago by Simon Charette

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