How do I inspectdb 1 table from database which Contains 1000 tables How do I inspectdb 1 table from database which Contains 1000 tables django django

How do I inspectdb 1 table from database which Contains 1000 tables


You can generate the model of a single table, running this command

python manage.py inspectdb TableName > output.py

This works also if you want to generate the model of a view


You can do it in the python console, or in *.py file:

from django.core.management.commands.inspectdb import Commandfrom django.conf import settingsfrom your_project_dir.settings import DATABASES  #  replace `your_project_dir`settings.configure()settings.DATABASES = DATABASESCommand().execute(table_name_filter=lambda table_name: table_name in ('table_what_you_need_1', 'table_what_you_need_2', ), database='default')

https://github.com/django/django/blob/master/django/core/management/commands/inspectdb.py#L32


You can do it by the following command in Django 2.2 or above

python manage.py inspectdb --database=[dbname] [table_name] > output.py