---
django: 6.1.3 (f16e25dcb9fe55734ba4ea2b00ac34405b7df74a)
---

# The system check framework and --deploy guards

How does `CheckRegistry` collect checks from models, fields, settings, and third-party apps, and which security mistakes are caught only when `--deploy` is passed?

Before Django runs migrations, starts `"runserver"`, or executes your test suite, it runs a fast static verification pass across every model, field, URLconf, template backend, cache config, and installed app. That verification engine lives in `django/core/checks/` — centered on one singleton **`CheckRegistry`** (`django/core/checks/registry.py:CheckRegistry`).

## Two registries inside `CheckRegistry` — and why `Tags.database` is opt-in

Open `CheckRegistry.__init__` and `CheckRegistry.register` (`django/core/checks/registry.py:CheckRegistry.register`):

```python
self.registered_checks = set()
self.deployment_checks = set()
```

Every subsystem in Django (models, fields, admin, auth, security, templates, tasks, staticfiles, URLs) registers check functions tagged with constants from `Tags` (`django/core/checks/registry.py:Tags`) — such as `Tags.models`, `Tags.admin`, `Tags.security`, and `Tags.database` — returning lists of **`CheckMessage`** (`django/core/checks/messages.py:CheckMessage`) subclasses (`Debug` `10`, `Info` `20`, `Warning` `30`, `Error` `40`, `Critical` `50`). Anything at or above `"fail_level"` (`Error` `40` by default) aborts command startup with `SystemCheckError` unless explicitly listed in `"settings.SILENCED_SYSTEM_CHECKS"`.

Look closely at **two** checks that ordinary `"manage.py check"` intentionally skips:

1. **Deployment checks (`deploy=True`):** Functions registered via `"@register(Tags.security, deploy=True)"` live exclusively in **`CheckRegistry.deployment_checks`** (`21` checks in Django `6.1.3`!) — completely separate from the `30` always-on static checks in `"self.registered_checks"`. During normal development, `run_checks(include_deployment_checks=False)` never calls them, because local development servers run over plain HTTP with `DEBUG=True` and would drown in false alarms! You ONLY execute them when you run **`"python manage.py check --deploy"`** (ideally inside CI/CD against your production settings module!).
2. **Database checks (`Tags.database`):** Look at lines 90–94 of `django/core/checks/registry.py`: if `"tags"` is `None` AND `"databases"` is not explicitly passed, `CheckRegistry.run_checks` (`django/core/checks/registry.py:CheckRegistry.run_checks`) **filters out every `Tags.database` check** so static checks never open a live database connection! Passing `"--database default"` (or running `"manage.py test"`, where `DiscoverRunner.run_checks` passes active test aliases) turns them on.

## Running `check` vs. `check --deploy` on the desk project

Watch `"desk/"` (which has `DEBUG = False`, `ALLOWED_HOSTS` populated, and all security middleware installed, yet lacks production HTTPS headers and secure cookie flags) pass normal `check` with **`0`** issues while `check --deploy` immediately flags **four** production security warnings (`level=30`):

```text recording=ch13-tooling
2. CheckRegistry static checks vs --deploy checks on desk/
  registry_counts: registered=30 deployment=21 tags=14
  desk_check: static_issues=0 deploy_issues=4 deploy_ids=['security.W004(30)', 'security.W008(30)', 'security.W012(30)', 'security.W016(30)']
```

Look at those four exact deployment warnings caught only by `"--deploy"`:

- **`"security.W004"`:** `"SECURE_HSTS_SECONDS"` is unset (browsers will not enforce HTTP Strict Transport Security).
- **`"security.W008"`:** `"SECURE_SSL_REDIRECT"` is `False` (plain HTTP requests are not redirected to HTTPS).
- **`"security.W012"`:** `"SESSION_COOKIE_SECURE"` is `False` (session cookies could traverse an unencrypted HTTP link).
- **`"security.W016"`:** `"CSRF_COOKIE_SECURE"` is `False` (CSRF cookies could traverse plain HTTP).

Adding `"python manage.py check --deploy --fail-level WARNING"` against your production settings in CI ensures none of those four production omissions ever slips past local green builds.

Running `"manage.py runserver"` invokes these checks too — inside a surprisingly subtle two-process architecture that makes `AppConfig.ready` execute twice. We dissect the autoreloader next in [Why runserver runs two processes](autoreload.md).
