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
- Python
>=3.11 - Django
>=4.2,<6.0
Install the package:
pip install django-dbmlAdd django_dbml to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"django_dbml",
]Generate DBML for all installed models:
python manage.py dbmlWrite the schema to a file:
python manage.py dbml --output_file schema.dbmlGenerate DBML for a single app:
python manage.py dbml billingGenerate DBML for a single model:
python manage.py dbml billing.InvoiceWhen you target a specific app or model, django-dbml also includes the forward-related tables needed to keep the schema usable.
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.
python manage.py dbml --add_project_name "Backoffice"python manage.py dbml accounts billing crmpython manage.py dbml billing.Invoice billing.InvoiceLinepython manage.py dbml --output_file docs/schema.dbmlpython manage.py dbml --table_namespython manage.py dbml \
--add_project_name "Commerce Platform" \
--add_project_notes "Generated from production models." \
--output_file schema.dbmlpython manage.py dbml --group_by_app --color_by_appdjango-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 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.
This repository is managed with uv.
Bootstrap the environment:
make syncCommon commands:
make test
make lint
make buildRun the test suite against a specific Django series:
make test-django DJANGO_CONSTRAINT="django>=5.1,<5.2" PYTHON=3.13More development details are available in CONTRIBUTING.md and docs/development.md.
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
The initial code was based on https://github.com/hamedsj/DbmlForDjango