sportymsk
sportymsk

Reputation: 73

How to link existing tables in database to Django Models?

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?

Upvotes: 1

Views: 4425

Answers (1)

Prakhar Trivedi
Prakhar Trivedi

Reputation: 8526

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.

Upvotes: 7

Related Questions