juliocesar_io
juliocesar_io

Reputation: 27

Django RawQuerySet not working as expected

I ran a raw query just as the Django docs point:

Model.objects.raw('SELECT * FROM model')

and I got this result, Why it only shows the object?

<RawQuerySet: 'SELECT * FROM model'>

Upvotes: 0

Views: 956

Answers (1)

dahrens
dahrens

Reputation: 3959

Because one (very powerful) feature of a queryset is, that it does not hit the database until necessary. You might slice it to get the results.

Model.objects.raw('SELECT * FROM model')[:]

Read the first paragraph of the queryset docs to learn more about other ways to execute the underlying query.

Upvotes: 1

Related Questions