【发布时间】:2019-05-14 22:49:00
【问题描述】:
当我创建一个 Location 实例时,我得到了这个错误。
django.db.utils.IntegrityError: null value in column "address" violates not-null constraint
这是我的定位模型。
class Location(DirtyFieldsMixin, TimeStampedModel):
id = SmallUUIDField(
default=uuid_default(),
primary_key=True,
db_index=True,
editable=False,
verbose_name='ID'
)
name = models.CharField(max_length=100)
address = models.TextField(blank=True)
timezone = models.CharField(null=True, max_length=100)
phone = PhoneNumberField(blank=True)
email = models.EmailField(blank=True)
发布位置时,有效负载看起来像这样。
{'name': 'Beij the Sage', 'address': None, 'latlon': None, 'timezone': 'America/Los_Angeles', 'phone': '', 'email': ''}
我的模型有blank=True,所以None 的值是address 不应该抛出这个错误。
【问题讨论】:
标签: python django django-models django-rest-framework