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

本小妞迷上赌 提交于 2019-12-03 07:44:04

问题


I got a schema which Contains 1000 tables,and many of them I don't need, how can I just inspectdb the just tables that I need?


回答1:


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

from django.core.management.commands.inspectdb import Command
from django.conf import settings
from your_project_dir.settings import DATABASES  #  replace `your_project_dir`

settings.configure()
settings.DATABASES = DATABASES

Command().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




回答2:


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



来源:https://stackoverflow.com/questions/27163702/how-do-i-inspectdb-1-table-from-database-which-contains-1000-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!