mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #27979 -- Made MySQL raise IntegrityError rather than OperationalError when saving negative numbers in PositiveInteger fields.
This commit is contained in:
parent
08c8c3ead9
commit
dd82f33271
2 changed files with 14 additions and 2 deletions
|
@ -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):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue