1

我正在尝试在 Django 中排除某些表来执行检查命令我发现了这个问题:How do I inspectdb 1 table from database which contains 1000 tables similar to mine 但问题是当我运行相同的代码时我得到一个奇怪的错误 script.py

from django.core.management.commands.inspectdb import Command
from django.conf import settings
from SFP_test.settings import DATABASES

if not settings.configured:
    settings.configure()
settings.DATABASES = DATABASES

Command().execute(table_name_filter=lambda table_name: table_name in ('base_table', 'bp_table', ), database='sfp')

错误:

Traceback (most recent call last):
  File "/Users/user/PycharmProjects/SFP_crud_test/generateapp.py", line 24, in <module>
    Command().execute(table_name_filter=lambda table_name: table_name in ('base_table', 'bp_table', ), database='sfp')
  File "/Users/user/PycharmProjects/SFP_test/venv/lib/python3.7/site-packages/django/core/management/base.py", line 348, in execute
    if options['force_color'] and options['no_color']:
KeyError: 'force_color'
4

1 回答 1

0

尝试以下

python manage.py inspectdb <tableName> --database <DatabaseName> > output.py

output.py将有你的表模型

此外,请确保您的数据库配置settings.py如下

DatabaseName': {
       'NAME': 'DbName',
       'ENGINE': 'django.db.backends.postgresql',
       'HOST': 'HostName',
       'USER': 'user',
       'PORT': 9999,
       'OPTIONS': {
            'sslmode': 'require',
            'sslcert': 'cert',
            'sslkey': 'key',
        }
于 2020-06-26T04:56:21.833 回答