Fixed bug https://code.djangoproject.com/ticket/19607

Fixed crash on prefetch_related. See https://code.djangoproject.com/ticket/19607