How to link existing tables in database to Django Models?

4.3k Views Asked by At

I am learning Django and i need to know whether i can link a table already present in the database to a model (since, i heard that tables are created by Django for whatever models we are creating inside django app ).

If so, how can it be done?

1

There are 1 best solutions below

0
Prakhar Trivedi On BEST ANSWER

inspectdb works fine now. (Django 1.7+) Simply running manage.py inspectdb will create classes for all tables in database and display on console.

 $ python manage.py inspectdb

Save this as a file by using standard Unix output redirection:

 $ python manage.py inspectdb > models.py

Read further from here.