Hello,
In my app, I also had an app called user to separate the database of users from the database of records. These databases were called from the settings.py of the main app through a router
I am currently modifying this action and I want to create my own model for the user table and that is where I find the problem.
I get the error
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
I think it’s because I left the default database empty in the settings.py file, but I never had this problem before.
Next I show my files.
db_routers.py
class AuthRouter:
router_app_labels = {'auth', 'contenttypes', 'sessions', 'admin'}
def db_for_read(self, model, **hints):
if model._meta.app_label in self.router_app_labels:
return 'users_db'
return None
def db_for_write(self, model, **hints):
if model._meta.app_label in self.router_app_labels:
return 'users_db'
return None
def allow_relation(self, obj1, obj2, **hints):
if(
obj1._meta.app_label in self.router_app_labels or
obj2._meta.app_label in self.router_app_labels
):
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label in self.router_app_labels:
return db == 'users_db'
return None
class IntranetReclamacionesRouter:
def db_for_read(self, model, **hints):
if model._meta.app_label == 'reclamaciones':
return 'intranet_db'
return None
def db_for_write(self, model, **hints):
if model._meta.app_label == 'reclamaciones':
return 'intranet_db'
return None
def allow_relation(self, obj1, obj2, **hints):
if (
obj1._meta.app_label == 'reclamaciones' or
obj2._meta.app_label == 'reclamaciones'
):
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label == 'reclamaciones':
return db == 'intranet_db'
return None
Setting.py
DATABASES = {
'default': {},
'users_db': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'users',
'USER': '',
'PASSWORD': '',
'HOST': 'xxxxxxx',
'PORT': '3306'
},
'intranet_db': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'intranet',
'USER': '',
'PASSWORD': '',
'HOST': 'xxxxxxx,
'PORT': '3306'
}
}
DATABASE_ROUTERS = ['routers.db_routers.AuthRouter','routers.db_routers.IntranetReclamacionesRouter']
Any idea what could happen?
Thank you