2

My Django Model:

from localflavor.us.forms import USPhoneNumberField

class Profile(models.Model):
    cellPhone = USPhoneNumberField(null=True, blank=True,)

This gives me the following error when I do a manage.py syncdb:

cellPhone = USPhoneNumberField(null=True, blank=True,)
TypeError: __init__() got an unexpected keyword argument 'null'

How can I make this field optional if it won't let me declare it as null=True like I do for so many other fields?

Saqib Ali
  • 11,931
  • 41
  • 133
  • 272
  • Noise alert - here is the link to [source code](https://github.com/django/django-localflavor/blob/master/localflavor/us/forms.py#L42-L45) – Anshul Goyal Jul 31 '14 at 20:51

1 Answers1

5

USPhoneNumberField is a form type, not a model type

The usage (typically) is:

class Profile(models.Model):
    cellPhone = models.CharField(max_length=20, null=True, blank=True,)

and forms.py

class ProfileForm(forms.Form): #or forms.ModelForm
    cellPhone = forms.USPhoneNumberField(...)

Here is the documentation

class localflavor.us.models.PhoneNumberField(*args, **kwargs) A CharField that checks that the value is a valid U.S.A.-style phone number (in the format XXX-XXX-XXXX).

karthikr
  • 97,368
  • 26
  • 197
  • 188