[Django]-How to generate data model from sql schema in Django?

54👍

Yes it is possible, using the inspectdb command:

python manage.py inspectdb

or

python manage.py inspectdb > models.py

to get them in into the file

This will look at the database configured in your settings.py and outputs model classes to standard output.

As Ignacio pointed out, there is a guide for your situation in the documentation.

👤TM.

2👍

If each table has an autoincrement integer PK then you can use the legacy database instructions.

Leave a comment