我有以下 Django 模型:
class Customer(models.Model):
email = models.EmailField(unique=True)
在我的测试用例中,我在没有电子邮件的情况下实例化它。
class CustomerTestCase(TestCase):
def test_that_customer_can_be_created_with_minimum_data(self):
customer = Customer.objects.create()
print(customer.__dict__)
我希望它会引发错误,但它会创建一个带有空字段的记录email
。null=False
如果我明确地说and ,也会发生同样的事情blank=False
。相反,它只打印空电子邮件。
{'email': ''}
我错过了什么?