[Answered ]-Django 1.9 migrate for the first time is not creating tables

2👍

The problem is that your CustomUser.objects.get(pk=1) query is running when the URL config is loaded and imports the views, before the tables have even been created. You can fix this by moving the code into a get_queryset method.

class PostViewSet(ModelViewSet):
    def get_queryset(self):
        some_user = CustomUser.objects.get(pk=1)
        return Post.objects.filter(
            Q(poster=some_user) |
            Q(poster__friends__creator=some_user) |
            Q(poster__friendship_creator__friend=some_user)).distinct()
    serializer_class = PostSerializer

Leave a comment