Django tests don't raise integrity error for CharField

前端 未结 1 608
暖寄归人
暖寄归人 2021-01-23 01:20

If have the following Django (1.4) model:

from django.db import models

class SimpleModel(models.Model):
    name = models.CharField(max_length=100)
相关标签:
1条回答
  • 2021-01-23 02:02

    Django never stores NULL for empty CharField or TextField types. It stores an empty string (''). So that's why you don't get an IntegrityError for null=False.

    As for blank=False, that only affects forms. It just makes the form set the field as required=True so it won't validate unless it has a value. It doesn't affect the database or your ability to manually set a blank value outside of a form.

    0 讨论(0)
提交回复
热议问题