Grancein
Grancein

Reputation: 652

Create sql schema from django models or migrations

I created different models with django 1.8. Now, to enable other people to have a quickly comprehension, I would create a sql schema from the models or from the migration files (even only from the initial migration file).
Someone knows how does it?

Upvotes: 0

Views: 4416

Answers (2)

lmr2391
lmr2391

Reputation: 611

If you just want to show the database structure to others, I would rather recommend using the graph_models command from django_extensions: http://django-extensions.readthedocs.io/en/latest/graph_models.html

For example typing

python manage.py graph_models -a -g models.png

creates a graph with the individual models as nodes and their relations as arcs (assuming you have graphviz installed). You can also create a dot-file and render it however you like

Upvotes: 1

Krzysztof Szularz
Krzysztof Szularz

Reputation: 5249

You can squash all migrations for a moment, or delete them for a sec and generate new initial one and then run this command:

https://docs.djangoproject.com/en/1.11/ref/django-admin/#django-admin-sqlmigrate

Upvotes: 2

Related Questions