django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. router.py given

Viewed 31

database setting

I know settings.DATABASES is correctly configured as I've already created models which then Django used to create tables in the DB but for whatever reason it is now causing this error. You can also see that I have already "supplied the ENGINE value". and router.py one more thing first database customer I did not get any error during makemigration command and successfully created table in database

DATABASES ={
    'default': {},
    'users':{
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'customer',
        'USER': 'postgres',
        'PASSWORD': '123',
     },
     'listings':{
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'listing',
        'USER': 'postgres',
        'PASSWORD': '123',
     },
}
DATABASE_ROUTERS = ['customer.router.AuthRouter', 'list.router.ListingRouter']

router.py





class ListingRouter:
    route_app_labels = {'listing'}
    def db_for_read(self, model, **hints):
        if model._meta.app_label in self.route_app_labels:
            return 'listings'
        return None
    def db_for_write(self, model, **hints):
        if model._meta.app_label in self.route_app_labels:
            return 'listings'
        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 == 'listings'
        return None

database setting and router.py attached 1 2

1 Answers

You need to provide a value for your default database as well, so:

DATABASES = {
    'default': {
        'ENGINE': '…',
        'NAME': '…',
        'USER': '…',
        'PASSWORD': '…',
    },
    'users': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'customer',
        'USER': 'postgres',
        'PASSWORD': '123',
    },
    'listings': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'listing',
        'USER': 'postgres',
        'PASSWORD': '123',
    },
}

If users is the default, you thus specify this one:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'customer',
        'USER': 'postgres',
        'PASSWORD': '123',
    },
    'listings': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'listing',
        'USER': 'postgres',
        'PASSWORD': '123',
    },
}
Related