| | 225 | The database API |
|---|
| | 226 | ================ |
|---|
| | 227 | |
|---|
| | 228 | How can I see the raw SQL queries Django is running? |
|---|
| | 229 | ---------------------------------------------------- |
|---|
| | 230 | |
|---|
| | 231 | Make sure your Django ``DEBUG`` setting is set to ``True``. Then, just do |
|---|
| | 232 | this:: |
|---|
| | 233 | |
|---|
| | 234 | >>> from django.core.db import db |
|---|
| | 235 | >>> db.queries |
|---|
| | 236 | [{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls', |
|---|
| | 237 | 'time': '0.002'}] |
|---|
| | 238 | |
|---|
| | 239 | ``db.queries`` is only available if ``DEBUG`` is ``True``. It's a list of |
|---|
| | 240 | dictionaries in order of query execution. Each dictionary has the following:: |
|---|
| | 241 | |
|---|
| | 242 | ``sql`` -- The raw SQL statement |
|---|
| | 243 | ``time`` -- How long the statement took to execute, in seconds. |
|---|
| | 244 | |
|---|