Index: django/db/models/fields/related.py
===================================================================
--- django/db/models/fields/related.py	(revision 8363)
+++ django/db/models/fields/related.py	(working copy)
@@ -423,7 +423,7 @@
                     if isinstance(obj, self.model):
                         new_ids.add(obj._get_pk_val())
                     else:
-                        new_ids.add(obj)
+                        new_ids.add(self.model._meta.pk.to_python(obj))
                 # Add the newly created or already existing objects to the join table.
                 # First find out which items are already added, to avoid adding them twice
                 cursor = connection.cursor()
@@ -453,7 +453,7 @@
                     if isinstance(obj, self.model):
                         old_ids.add(obj._get_pk_val())
                     else:
-                        old_ids.add(obj)
+                        old_ids.add(self.model._meta.pk.to_python(obj))
                 # Remove the specified objects from the join table
                 cursor = connection.cursor()
                 cursor.execute("DELETE FROM %s WHERE %s = %%s AND %s IN (%s)" % \
