Reputation: 31
If a database table contains 100 fields, and a django application utilises only a few fields say 1 or 2, does the corresponding django model needs to be declared with 100 fields?
Upvotes: 3
Views: 502
Reputation: 27321
No, you do not need to declare the Django model with all the fields from the database.
Upvotes: 2
Reputation: 2693
Django comes with a utility called inspectdb that can create models by introspecting an existing database
python manage.py inspectdb
Save this as a file by using standard Unix output redirection:
python manage.py inspectdb > models.py
This will reduce the stress of manually defining the model.
Ref: https://docs.djangoproject.com/en/1.10/howto/legacy-databases/
Upvotes: 0