Sometimes, we want to generate Python Django models from the database.
In this article, we’ll look at how to generate Python Django models from the database.
How to generate Python Django models from the database?
To generate Python Django models from the database, we run manage.py
with the inspectdb
option.
For instance, we run
python manage.py inspectdb > models.py
to make Django inspect the database the app is connected to, generate the models, and save the model class code to models.py
.
Conclusion
To generate Python Django models from the database, we run manage.py
with the inspectdb
option.