Skip to main content

Overview

The load_initial_data management command loads the complete bakery demo dataset from a fixture file (bakerydemo.json) and copies associated media files to the configured storage backend. This command is essential for setting up a fresh instance of the Wagtail Bakery Demo with sample content.
This command automatically handles both local file storage and cloud storage providers (like AWS S3) by copying media files to the configured default_storage backend.

What It Does

The command performs the following operations in sequence:
1

Copy Media Files

Recursively copies all media files from bakerydemo/base/fixtures/media/ to the configured storage backend (local filesystem or cloud storage)
2

Clean Default Content

Removes auto-generated Wagtail site and page instances:
  • Deletes the default localhost site
  • Removes the “Welcome to your new Wagtail site!” page
3

Load Fixture Data

Loads the complete database fixture from bakerydemo.json containing:
  • Page structure (HomePage, Blog, Breads, Locations)
  • Snippets (People, Countries, Bread Types, Ingredients)
  • Images and documents
  • Site configuration
4

Update Search Index

Rebuilds the Wagtail search index for all pages
5

Rebuild References

Rebuilds the references index for content relationships

Usage

python manage.py load_initial_data

Command Arguments

This command does not accept any arguments or options.

Example Output

$ python manage.py load_initial_data
Copying media files to configured storage...
Awesome. Your data is loaded! The bakery's doors are almost ready to open...

Source Code Location

bakerydemo/base/management/commands/load_initial_data.py

Implementation Details

File Storage Handling

The command uses a recursive _copy_files() method to traverse the fixtures media directory:
def _copy_files(self, local_storage, path):
    """
    Recursively copy files from local_storage to default_storage.
    """
    directories, file_names = local_storage.listdir(path)
    for directory in directories:
        self._copy_files(local_storage, path + directory + "/")
    for file_name in file_names:
        with local_storage.open(path + file_name) as file_:
            default_storage.save(path + file_name, file_)
This approach ensures media files work correctly whether you’re using local storage or cloud providers like AWS S3.

Fixture Data

The fixture file is loaded from:
bakerydemo/base/fixtures/bakerydemo.json
This JSON file contains approximately 542KB of serialized Django model data.
This command will fail if:
  • The bakerydemo.json fixture file is missing or corrupted
  • The fixtures media directory is not accessible
  • Database migrations have not been applied
  • The configured storage backend is not accessible

When to Use

  • Initial Setup: When deploying a new instance of the Wagtail Bakery Demo
  • Development: Resetting your local development environment to a known state
  • Testing: Setting up test environments with consistent sample data
  • Demos: Preparing environments for demonstrations or presentations

See Also

Build docs developers (and LLMs) love