  from django.test import TestCase
  from rest_framework import serializers
  from rest_framework.tests.models import NullableForeignKeySource, ForeignKeyTarget
  
  
  class NullableSlugSourceSerializer(serializers.ModelSerializer):
      target = serializers.SlugRelatedField(slug_field='name', null=True)
  
 
</s> remove class NullableSlugSourceSerializer(serializers.ModelSerializer):
 </s> add class ForeignKeyTargetSerializer(serializers.ModelSerializer):
    sources = serializers.ManySlugRelatedField(slug_field='name')

    class Meta:
        model = ForeignKeyTarget


class ForeignKeySourceSerializer(serializers.ModelSerializer):
    target = serializers.SlugRelatedField(slug_field='name')

    class Meta:
        model = ForeignKeySource


class NullableForeignKeySourceSerializer(serializers.ModelSerializer): </s> remove             msg = self.error_messages['invalid']
            raise ValidationError(msg)
 </s> add             msg = self.error_messages['incorrect_type']
            raise ValidationError(msg % type(value).__name__) </s> remove         serializer = NullableSlugSourceSerializer(data=data)
 </s> add         serializer = NullableForeignKeySourceSerializer(data=data) </s> remove         serializer = NullableSlugSourceSerializer(data=data)
 </s> add         serializer = NullableForeignKeySourceSerializer(data=data) </s> remove             msg = self.error_messages['invalid']
            raise ValidationError(msg)
 </s> add             msg = self.error_messages['incorrect_type']
            raise ValidationError(msg % type(value).__name__)
from rest_framework.tests.models import NullableForeignKeySource, ForeignKeySource, ForeignKeyTarget
  from django.test import TestCase
  from rest_framework import serializers
from rest_framework.tests.models import NullableForeignKeySource, ForeignKeySource, ForeignKeyTarget
  
  
  class NullableSlugSourceSerializer(serializers.ModelSerializer):
      target = serializers.SlugRelatedField(slug_field='name', null=True)
  
keep keep replace keep keep keep keep keep
 Raise Validation Errors when relationships receive incorrect types. Fixes #590. 
rest_framework/tests/relations_slug.py