liveBook · Manning

Dbshell command

As explained in Django in Action

The dbshell command is a Django management command that opens the interactive command-line tool for the database configured by a project.

Run `python manage.py dbshell` to open the interactive command-line tool for the database configured by a Django project. It provides one familiar entry point even when projects use different database systems; once inside, commands follow that database’s own tool. section 4.3

(venv) RiffMates$ python manage.py dbshell

Start the shell from the project directory with Django’s management command. section 4.3

With the default SQLite database, the prompt lets you inspect tables and run SQL directly:

  • SQLite displays an `sqlite>` prompt after starting. section 4.3
  • Use `.tables` to list tables, including Django’s built-in tables, migration-tracking tables, and the application’s model tables. section 4.3
  • Use `.schema bands_musician` to inspect the SQL used to create the table mapped from the `Musician` model. section 4.3
  • Distinguish SQLite dot commands from SQL statements: dot commands belong to the shell, while SQL queries operate directly on database data. section 4.3

How Django in Action covers it

How deep it goes
Explains invocation and SQLite inspection commands, but defers database-specific operations to the selected backend.
Examples
Uses `python manage.py dbshell`, `.tables`, and `.schema bands_musician` to inspect a RiffMates database.
What it assumes
Assumes a configured Django database and management-command access while introducing SQLite shell interaction through Django.
What you can do after
Operate the configured database’s interactive tool and inspect tables or execute backend-specific SQL.
How it connects
Connects Django ORM models and migrations with SQLite, SQL, database tables, and interactive database shells.

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.