From 07a73a2714a504ae487112c1679977fccc19b159 Mon Sep 17 00:00:00 2001 From: Dan Loewenherz Date: Tue, 30 Apr 2013 13:28:09 -0700 Subject: [PATCH] Fixed #20337 -- Clarified error message when database relation is not allowed. --- django/db/models/fields/related.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index fb38aa9c57..1b79e5bade 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -228,8 +228,7 @@ class SingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjectDescri value._state.db = router.db_for_write(value.__class__, instance=instance) elif value._state.db is not None and instance._state.db is not None: if not router.allow_relation(value, instance): - raise ValueError('Cannot assign "%r": instance is on database "%s", value is on database "%s"' % - (value, instance._state.db, value._state.db)) + raise ValueError('Cannot assign "%r": the current database router prevents this relation.' % value) related_pk = tuple([getattr(instance, field.attname) for field in self.related.field.foreign_related_fields]) if None in related_pk: @@ -328,8 +327,7 @@ class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjec value._state.db = router.db_for_write(value.__class__, instance=instance) elif value._state.db is not None and instance._state.db is not None: if not router.allow_relation(value, instance): - raise ValueError('Cannot assign "%r": instance is on database "%s", value is on database "%s"' % - (value, instance._state.db, value._state.db)) + raise ValueError('Cannot assign "%r": the current database router prevents this relation.' % value) # If we're setting the value of a OneToOneField to None, we need to clear # out the cache on any old related object. Otherwise, deleting the