diff --git a/tests/update/models.py b/tests/update/models.py index bfcc29bee9f..b56dd2258ec 100644 --- a/tests/update/models.py +++ b/tests/update/models.py @@ -46,3 +46,4 @@ class Foo(models.Model): class Bar(models.Model): foo = models.ForeignKey(Foo, models.CASCADE, to_field='target') + m2m_foo = models.ManyToManyField(Foo, related_name='m2m_foo') diff --git a/tests/update/tests.py b/tests/update/tests.py index 55a8e24c6ac..ba7ffd5c880 100644 --- a/tests/update/tests.py +++ b/tests/update/tests.py @@ -139,6 +139,15 @@ class AdvancedTests(TestCase): bar_qs.update(foo=b_foo) self.assertEqual(bar_qs[0].foo_id, b_foo.target) + def test_update_m2m_field(self): + msg = ( + 'Cannot update model field ' + ' ' + '(only non-relations and foreign keys permitted).' + ) + with self.assertRaisesMessage(FieldError, msg): + Bar.objects.update(m2m_foo='whatever') + def test_update_annotated_queryset(self): """ Update of a queryset that's been annotated.