Django extension aimed to generate DBML from installed models.
Project description
django-dbml
django-dbml is a Django app that generates a DBML schema from your Django models.
It is useful when you want to:
- visualize your schema in tools that understand DBML
- document an existing Django project
- export a model-based schema for reviews, planning, or onboarding
The generated output includes:
- tables
- foreign key and one-to-one relationships
- autogenerated many-to-many join tables
- indexes and unique constraints
- enums derived from Django field choices
- notes derived from model and field metadata
Requirements
- Python
>=3.11 - Django
>=4.2,<6.0
Installation
Install the package:
pip install django-dbml
Add django_dbml to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"django_dbml",
]
Quick Start
Generate DBML for all installed models:
python manage.py dbml
Write the schema to a file:
python manage.py dbml --output_file schema.dbml
Generate DBML for a single app:
python manage.py dbml billing
Generate DBML for a single model:
python manage.py dbml billing.Invoice
When you target a specific app or model, django-dbml also includes the forward-related tables needed to keep the schema usable.
Command Reference
The management command is:
python manage.py dbml [app_label[.ModelName] ...] [options]
Supported options:
--output_file PATHWrite the generated DBML to a file instead of stdout.--table_namesUse the underlying database table names instead of Django model labels such asapp_label.ModelName.--group_by_appAddTableGroupblocks grouped by app/module.--color_by_appAddheadercolorto each table based on its app/module.--add_project_name NAMESet the DBML project name.--add_project_notes TEXTSet the DBML project notes.--disable_update_timestampDo not append theLast Updated At ... UTCline to the project notes.
Examples
Generate the whole project
python manage.py dbml --add_project_name "Backoffice"
Generate a subset of apps
python manage.py dbml accounts billing crm
Generate a subset of models
python manage.py dbml billing.Invoice billing.InvoiceLine
Save output to a file
python manage.py dbml --output_file docs/schema.dbml
Use physical table names instead of model labels
python manage.py dbml --table_names
Add project metadata
python manage.py dbml \
--add_project_name "Commerce Platform" \
--add_project_notes "Generated from production models." \
--output_file schema.dbml
Group and color tables by app
python manage.py dbml --group_by_app --color_by_app
How Metadata Is Mapped
django-dbml extracts useful schema notes from Django metadata when available.
Model-level metadata:
- model docstrings are emitted as table notes
db_table_commentis emitted as a table note- when
--table_namesis not used, the DB table name is added to the note
Field-level metadata:
help_textis emitted as a field noteverbose_nameis emitted as a field notedb_commentis emitted as a field notechoicesare converted into DBML enumsdefault,null,unique, and primary key information are included in field attributes
Relationship handling:
ForeignKeyis rendered as a one-to-many referenceOneToOneFieldis rendered as a one-to-one reference- autogenerated
ManyToManyFieldjoin tables are rendered as explicit DBML tables and references
Example Output
Example command:
python manage.py dbml library --add_project_name "Library"
Example shape of the generated DBML:
Project "Library" {
database_type: 'PostgreSQL'
Note: '''Generated from Django models.
Last Updated At 03-30-2026 02:15PM UTC'''
}
Table library.Book {
title char [not null]
author_id bigint [not null]
}
ref: library.Book.author_id > library.Author.id
The exact output depends on your models, database backend, indexes, choices, and comments.
Development
This repository is managed with uv.
Bootstrap the environment:
make sync
Common commands:
make test
make lint
make build
Run the test suite against a specific Django series:
make test-django DJANGO_CONSTRAINT="django>=5.1,<5.2" PYTHON=3.13
More development details are available in CONTRIBUTING.md and docs/development.md.
Contributors
Thanks to the people who helped improve this project through patches and pull requests, including:
- Michel Wilhelm
- Ee Durbin
- Mathieu Hinderyckx
- Rebecca Sutton Koeser
- Evgeny
- Nick Budak
- jcp
- johnecon
Credits
The initial code was based on https://github.com/hamedsj/DbmlForDjango
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_dbml-1.1.2.tar.gz.
File metadata
- Download URL: django_dbml-1.1.2.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adb29d7d153dfa5e6f2aa5512f944a97b8508829a8940398634af6b9335a5c42
|
|
| MD5 |
b2e1b56779c39dd7e3200c258bbb5c4d
|
|
| BLAKE2b-256 |
dd98fc4ffaf5b08dfea3189aa12632d682314af1d5a878a69c3f395ea2a5a1e7
|
Provenance
The following attestation bundles were made for django_dbml-1.1.2.tar.gz:
Publisher:
production.yml on makecodes/django-dbml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_dbml-1.1.2.tar.gz -
Subject digest:
adb29d7d153dfa5e6f2aa5512f944a97b8508829a8940398634af6b9335a5c42 - Sigstore transparency entry: 1201650442
- Sigstore integration time:
-
Permalink:
makecodes/django-dbml@e642a8bee9992c183f9fa89c2d47e76988a2410c -
Branch / Tag:
refs/tags/1.1.2 - Owner: https://github.com/makecodes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
production.yml@e642a8bee9992c183f9fa89c2d47e76988a2410c -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_dbml-1.1.2-py3-none-any.whl.
File metadata
- Download URL: django_dbml-1.1.2-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
066beae34616031a382e74c5c50d9f34e1e4dc4919f56e9f782bb5fb5daab73d
|
|
| MD5 |
6a1b0a8bf8fa5d15b0caa66279abbe83
|
|
| BLAKE2b-256 |
897123e472026a1f96113fff3d35b3c4328c1e01552532256cf130ea0e99c3bd
|
Provenance
The following attestation bundles were made for django_dbml-1.1.2-py3-none-any.whl:
Publisher:
production.yml on makecodes/django-dbml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_dbml-1.1.2-py3-none-any.whl -
Subject digest:
066beae34616031a382e74c5c50d9f34e1e4dc4919f56e9f782bb5fb5daab73d - Sigstore transparency entry: 1201650465
- Sigstore integration time:
-
Permalink:
makecodes/django-dbml@e642a8bee9992c183f9fa89c2d47e76988a2410c -
Branch / Tag:
refs/tags/1.1.2 - Owner: https://github.com/makecodes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
production.yml@e642a8bee9992c183f9fa89c2d47e76988a2410c -
Trigger Event:
push
-
Statement type: