2
如果有以下的Django(1.4)模型:Django的测试不提高完整性错误CharField
from django.db import models
class SimpleModel(models.Model):
name = models.CharField(max_length=100)
而这个简单的测试:
from django.test import TestCase
from models import SimpleModel
from django.db import IntegrityError
class SimpleTest(TestCase):
def test_integrity_error(self):
with self.assertRaises(IntegrityError):
m = SimpleModel()
m.save()
随着数据库使用sqlite3的数据库。如果我现在使用python manage.py test <appname>
运行测试,则测试将以AssertionError: IntegrityError not raised
失败。
现在的问题是:为什么?
据我了解(或没想明白)的Django的默认值的字段是blank=False
和null=False
,所以我会假设节省的模型实例使用默认值(这是我想了CharField应该是一个空字符串)肯定会失败!那么,为什么不这样呢?