Django objects.all() empty query set, not empty in

2019-08-05 11:03发布

问题:

I have been using Django for the past 2 years with no issues at all, I am no rookie.

I recently created a new attribute for a model and added it to the mysql database.

Whenever I filter things using this attribute in my "views.py" i get an empty set, whenever I use the same exact line of code using "manage.py shell" it returns the expected queryset.

I have tried restarting the httpd service, the mysqld service and I have rebooted the system but nothing happens.

Does anyone know how to bypass this issue?

Here's the code I used to debug this issue:

Shell: It won't let me post pictures so here's the code:

>>>Session.objects.filter(cancellation_session=True)
>>>[<Session: Zumba Toning (Ladies)>]

views.py:

def gym_day2(request):
    return HttpResponse(str(Session.objects.filter(cancellation_session=True)))

HttpResponse:

[]

Please Help!

回答1:

add . values or .values_list() after the statement , Session.objects.filter(cancellation_session=True).values(´field´)