简体   繁体   English

为什么不能将Django模型的USPhoneNumberField设置为null = True,blank = True?

[英]Why can't I set my Django Model's USPhoneNumberField to null=True, blank=True?

My Django Model: 我的Django模型:

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: 当我执行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? 如果不允许我像其他许多字段一样将其声明为null = True,如何使该字段为可选?

USPhoneNumberField is a form type, not a model type USPhoneNumberFieldform类型,而不是模型类型

The usage (typically) is: 用法(通常)是:

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

and forms.py 和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 USA-style phone number (in the format XXX-XXX-XXXX). class localflavor.us.models.PhoneNumberField(* args,** kwargs)一个CharField,它检查该值是否为有效的美国式电话号码(格式为XXX-XXX-XXXX)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 完整性错误不是 NULL 约束失败,即使我在 model 中设置了空白=真,空=真 - Integrity Error NOT NULL constraint failed even though I have set blank=True, null=True in my model Django模型blank = True,但是sql总是NOT NULL - Django model blank=True, but sql always NOT NULL 为什么我不能将 True 存储在 Set 中? - Why can't I store True in a Set? 我设置 null = true 和 blank = true 但仍然得到“django.db.utils.IntegrityError: (1048, "Column 'massenger_name' cannot be null")" - i set null = true and blank = true but still get "django.db.utils.IntegrityError: (1048, "Column 'massenger_name' cannot be null")" 尽管将null设置为true并将blank设置为true,但Django中的NOT NULL约束失败错误 - NOT NULL constraint failed error in django despite having null set to true and blank set to true Django Admin 无法识别模型中的 blank=True - Django Admin doesn't recognise blank=True in model 默认情况下,Django模型字段中的“ default =…”是否设置为“ blank = True”? - Does 'default=…' in Django model fields set 'blank=True' by default? 即使我在 Model 中设置了“blank=True”,Django Admin 中仍需要字段 - Field is required in the Django Admin even though I have set "blank=True" in the Model Django DateTimeField定义为blank = True,null = True但不允许null - Django DateTimeField Defined as blank=True, null=True but doesn't allow null Django机型设置blank=True时如何区分需要null=True的字段? - How to distinguish field that requires null=True when blank=True is set in Django models?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM