Django cannot be both deferred and traversed using select_related at the same time

student_list = Student.objects.only('name').select_related('grades')

由于是表关联,此时没有查询关联表 grades 的任何内容, 报错

修改为:
       student_list = Student.objects.only('name', 'grades__title').select_related('grades')

你可能感兴趣的:(Django cannot be both deferred and traversed using select_related at the same time)