liveBook · Manning

Dumpdata

As explained in Django in Action

dumpdata is a Django management command that serializes database data, optionally filtered by application, into a fixture.

dumpdata is a Django management command that serializes database data into a fixture. It writes JSON to the screen by default and can restrict output to selected applications. section 4.9

The resulting text preserves object IDs and relationships, so it can represent the state needed to recreate involved tables. Redirect the output to a file when preparing reusable fixture data. section 4.9

Export and inspect band data

Run `python manage.py dumpdata bands | python -m json.tool` to export the bands application and pretty-print its JSON. The output contains serialized musicians and bands, including primary keys and related musician IDs. section 4.9

(venv) RiffMates$ python manage.py dumpdata bands | python -m json.tool

See the command pipeline used to produce human-readable fixture output. section 4.9

Save a fixture with shell redirection, then place it in an app's fixtures directory for loading later. Treat the file as machine-readable text: editor-added byte-order marks or changed newline characters can prevent successful loading. section 4.9

How Django in Action covers it

How deep it goes
Explains JSON serialization, object relationships, shell redirection, and fixture handling, but does not detail command options.
Examples
Uses the bands application, musicians, bands, JSON pretty-printing, shell redirection, and a fixtures directory.
What it assumes
Assumes a Django project with database data and introduces fixtures as serialized text representations of that data.
What you can do after
Operate Django's dumpdata command to export selected application data and save it as a fixture file.
How it connects
Connects fixtures with JSON, Django management commands, application data, object IDs, and loaddata.

Related concepts

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.