为什么唯一必需的CharField在空时不会出现IntegrityError?

时间:2017-10-18 08:00:31

标签: mysql django django-models

使用以下模型:

class Client(models.Model):
    name = models.CharField(max_length=50, unique=True)
    created_at = models.DateTimeField(auto_now_add=True, editable=False)
    modified_at = models.DateTimeField(auto_now=True, editable=False)

此测试失败:

def test_no_name_error(self):
    '''Ensure an Error is raised when creating a client with no name
    '''
    with self.assertRaises(IntegrityError):
        client = Client.objects.create()

测试失败了:

FAIL: test_no_name_error (projects.tests.test_models.ClientModelTests)
Ensure an Error is raised when creating a client with no name
----------------------------------------------------------------------
    client = Client.objects.create()
AssertionError: IntegrityError not raised

我正在使用mysql

0 个答案:

没有答案