Categories
Python Answers

How to generate Python Django models from the database?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *