Index: django/db/models/base.py
===================================================================
--- django/db/models/base.py	(revision 16519)
+++ django/db/models/base.py	(working copy)
@@ -449,6 +449,37 @@
             return getattr(self, field_name)
         return getattr(self, field.attname)
 
+       def refresh_foreign_keys(self):
+        """
+        Refreshes all foreign keys. Should be used before saving. If the primary
+        key of a foreign key changed after setting the related object to the
+        model it can not be refreshed automatically.
+        """
+
+        # Get all foreign keys of this model. Attname and name must be equal.
+        # attname.......Presents the property of this model in which field the
+        #               duplicated primary key is saved in the database.
+        # name..........Presents the reference to the object where the original
+        #               primary key is saved.
+        fks = [(f.attname, f.name) for f in self._meta.local_fields if type(f) == ForeignKey]
+
+        for (db_ref, fk_ref) in fks:
+            # If db_ref already exists we do not make unneccessary db-queries,
+            # because the related object is already set in the correct.
+            if not getattr(self, db_ref) and hasattr(self, fk_ref):
+
+                # raise an error if a primary key of the related object does
+                # not exist (if it is not saved until now)
+                if getattr(self, fk_ref).pk == None:
+                    print type(str(fk_ref))
+                    raise ValueError("Cannot find a primary key for " + str(fk_ref) +
+                        " as a foreign key in an instance of " + self.__class__.__name__ +
+                        ". Have you already saved the " + str(fk_ref) + " object?")
+
+                # If the duplicated key is not the real one, set the real one
+                if getattr(self, db_ref) != getattr(self, fk_ref).pk:
+                    setattr(self, db_ref, getattr(self, fk_ref).pk)
+		
     def save(self, force_insert=False, force_update=False, using=None):
         """
         Saves the current instance. Override this in a subclass if you want to
@@ -486,6 +517,11 @@
         if origin and not meta.auto_created:
             signals.pre_save.send(sender=origin, instance=self, raw=raw, using=using)
 
+        # Refresh the references of foreign keys. Primary keys of referenced
+        # objects may changed in the object but not in the database field of
+        # this model.
+        self.refresh_foreign_keys()
+						
         # If we are in a raw save, save the object exactly as presented.
         # That means that we don't try to be smart about saving attributes
         # that might have come from the parent class - we just save the
