diff options
| author | Tim Graham <timograham@gmail.com> | 2017-09-29 14:50:51 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-09-29 15:20:32 -0400 |
| commit | dd82f3327124fd2762cf6df2ac8c6380772bf127 (patch) | |
| tree | ff5d12e59a4e0b053dd695b4432612c860428a58 /tests/model_fields/test_integerfield.py | |
| parent | 08c8c3ead97893ec0e1dece699525ad7ed27c2d7 (diff) | |
| download | django-dd82f3327124fd2762cf6df2ac8c6380772bf127.tar.gz | |
Fixed #27979 -- Made MySQL raise IntegrityError rather than OperationalError when saving negative numbers in PositiveInteger fields.
Diffstat (limited to 'tests/model_fields/test_integerfield.py')
| -rw-r--r-- | tests/model_fields/test_integerfield.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/model_fields/test_integerfield.py b/tests/model_fields/test_integerfield.py index 99d7b1797c..5c7ba47fbb 100644 --- a/tests/model_fields/test_integerfield.py +++ b/tests/model_fields/test_integerfield.py @@ -1,6 +1,8 @@ +import unittest + from django.core import validators from django.core.exceptions import ValidationError -from django.db import connection, models +from django.db import IntegrityError, connection, models from django.test import SimpleTestCase, TestCase from .models import ( @@ -151,6 +153,13 @@ class PositiveIntegerFieldTests(IntegerFieldTests): model = PositiveIntegerModel documented_range = (0, 2147483647) + @unittest.skipIf(connection.vendor == 'sqlite', "SQLite doesn't have a constraint.") + def test_negative_values(self): + p = PositiveIntegerModel.objects.create(value=0) + p.value = models.F('value') - 1 + with self.assertRaises(IntegrityError): + p.save() + class ValidationTests(SimpleTestCase): |
