Reputation: 147
I'm trying to execute inspected command with the exclusion of some tables in Django I've found this question: How do I inspectdb 1 table from database which Contains 1000 tables similar to mine but the problem is when I run the same code i get a strange error 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')
error:
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'
Upvotes: 1
Views: 329
Reputation: 1
Try the following
python manage.py inspectdb <tableName> --database <DatabaseName> > output.py
output.py
will have your table Model
Additionally, ensure to have your database configured in settings.py
as following
DatabaseName': {
'NAME': 'DbName',
'ENGINE': 'django.db.backends.postgresql',
'HOST': 'HostName',
'USER': 'user',
'PORT': 9999,
'OPTIONS': {
'sslmode': 'require',
'sslcert': 'cert',
'sslkey': 'key',
}
Upvotes: 0