Search code examples
djangodjango-modelsdjango-databasedjango-database-functions

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?


Solution

  • 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.