mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #29126 -- Doc'd the behavior of QuerySet.update_or_create() with manually specified pks.
This commit is contained in:
@@ -444,6 +444,19 @@ class UpdateOrCreateTests(TestCase):
|
||||
self.assertEqual(obj.last_name, 'NotHarrison')
|
||||
|
||||
|
||||
class UpdateOrCreateTestsWithManualPKs(TestCase):
|
||||
|
||||
def test_create_with_duplicate_primary_key(self):
|
||||
"""
|
||||
If an existing primary key is specified with different values for other
|
||||
fields, then IntegrityError is raised and data isn't updated.
|
||||
"""
|
||||
ManualPrimaryKeyTest.objects.create(id=1, data='Original')
|
||||
with self.assertRaises(IntegrityError):
|
||||
ManualPrimaryKeyTest.objects.update_or_create(id=1, data='Different')
|
||||
self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, 'Original')
|
||||
|
||||
|
||||
class UpdateOrCreateTransactionTests(TransactionTestCase):
|
||||
available_apps = ['get_or_create']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user