반응형
1000개의 테이블이 포함된 데이터베이스에서 db 1 테이블을 검사하려면 어떻게 해야 합니까?
1000개의 테이블이 포함된 스키마를 얻었는데, 필요 없는 테이블이 많은데 어떻게 해야 필요한 테이블만 DB를 검사할 수 있습니까?
이 명령을 실행하여 단일 테이블의 모델을 생성할 수 있습니다.
python manage.py inspectdb TableName > output.py
뷰의 모형을 생성하려는 경우에도 작동합니다.
Python 콘솔 또는 *.py 파일에서 이 작업을 수행할 수 있습니다.
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
Django 2.2 이상에서 다음 명령으로 수행할 수 있습니다.
python manage.py inspectdb --database=[dbname] [table_name] > output.py
다음을 수행하여 원하는 테이블 모델을 얻을 수 있습니다.
python manage.py inspectdb table1 table2 tableN > output.py
이렇게 하면 원하는 테이블만 선택할 수 있습니다.
모델의 파이썬 코드를 생성하고 콘솔에 프로그래밍 방식으로 쓸 수 있습니다.
from django.core.management.commands.inspectdb import Command
command = Command()
command.execute(
database='default',
force_color=True,
no_color=False,
include_partitions=True,
include_views=True,
table=[
'auth_group',
'django_session'
]
)
세트table=[]
모든 테이블을 가져올 빈 목록
언급URL : https://stackoverflow.com/questions/27163702/how-do-i-inspectdb-1-table-from-database-which-contains-1000-tables
반응형
'sourcecode' 카테고리의 다른 글
구성 요소 Angular 2 내에서 리디렉션 (0) | 2023.08.27 |
---|---|
$.ajax 게시물은 Chrome에서 작동하지만 Firefox에서는 작동하지 않습니다. (0) | 2023.08.27 |
데이터 테이블에 AsEnumberable에 대한 정의가 없습니다. (0) | 2023.08.22 |
C# 문자열.IsNullOrEmpty Javascript 등가 (0) | 2023.08.22 |
SpringBoot 애플리케이션에서 SpringData JPA 및 SpringData Elastic 검색 리포지토리를 동일한 도메인 클래스에서 어떻게 사용합니까? (0) | 2023.08.22 |