Я использовал эту часть в файле настроек.
DATABASES = {
'default': {},
'user_db': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'user_db',
'USER': 'postgres',
'PASSWORD': 'test123',
'HOST' :'localhost',
'PORT':''
},
'wallet_db': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'wallet_db',
'USER': 'postgres',
'PASSWORD': 'test123',
'HOST' :'localhost',
'PORT':''
},
}
DATABASE_ROUTERS = ['userservice.dbRouter.UserRouter',
'walletservice.dbRouter.WalletRouter']
, а это мой файл router.py
class WalletRouter:
route_app_labels = {'walletservice'}
def db_for_read(self, model, **hints):
if model._meta.app_label in self.route_app_labels:
return 'wallet_db'
return None
def db_for_write(self, model, **hints):
if model._meta.app_label in self.route_app_labels:
return 'wallet_db'
return None
def allow_relation(self, obj1, obj2, **hints):
if (
obj1._meta.app_label in self.route_app_labels or
obj2._meta.app_label in self.route_app_labels
):
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label in self.route_app_labels:
return db == 'wallet_db'
return None
и аналогично я создал в другом приложении. Когда я делаю миграции и делаю миграцию, он работает нормально, как и предполагалось. но когда я пытаюсь создать суперпользователя, он показывает ошибку, и я не получаю ничего, чтобы решить эту проблему. Я провел все исследования, но не нашел никакого решения.
здесь ошибка
python manage.py createsuperuser --database=wallet_db
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
return super().execute(*args, **options)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 100, in handle
default_username = get_default_username()
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/contrib/auth/management/__init__.py", line 140, in get_default_username
auth_app.User._default_manager.get(username=default_username)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/query.py", line 411, in get
num = len(clone)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/query.py", line 258, in __len__
self._fetch_all()
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/query.py", line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/query.py", line 57, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1139, in execute_sql
sql, params = self.as_sql()
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 491, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 51, in pre_sql_setup
self.setup_query()
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 42, in setup_query
self.select, self.klass_info, self.annotation_col_map = self.get_select()
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 258, in get_select
sql, params = self.compile(col)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 423, in compile
sql, params = node.as_sql(self, self.connection)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/expressions.py", line 770, in as_sql
return "%s.%s" % (qn(self.alias), qn(self.target.column)), []
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 414, in quote_name_unless_alias
r = self.connection.ops.quote_name(name)
File "/home/goodwin/Desktop/env/intern_work/lib/python3.8/site-packages/django/db/backends/dummy/base.py", line 20, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
Уже пробовали обе команды python manage.py createduperuser и python manage.py createduperuser --databse = user_db может кто-нибудь помочь мне с этим. Спасибо.