简体   繁体   中英

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

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM