简体   繁体   English

django.core.exceptions.ImproperlyConfigured:settings.DATABASES 配置不正确。 请提供 ENGINE 值。 router.py 给出

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

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.我知道 settings.DATABASES 已正确配置,因为我已经创建了模型,然后 Django 用于在数据库中创建表,但无论出于何种原因,它现在都会导致此错误。 You can also see that I have already "supplied the ENGINE value".您还可以看到我已经“提供了 ENGINE 值”。 and router.py one more thing first database customer I did not get any error during makemigration command and successfully created table in database和 router.py 第一个数据库客户我在 makemigration 命令期间没有收到任何错误并成功在数据库中创建表

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路由器.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数据库设置和 router.py 附加 1 2

You need to provide a value for your default database as well, so:您还需要为default数据库提供一个值,因此:

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:如果users是默认值,您可以指定这个:

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',
    },
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 django.core.exceptions.ImproperlyConfigured:settings.DATABASES配置不正确。 请提供引擎值 - django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value raise ImproperlyConfigured(“settings.DATABASES 配置不正确。” django.core.exceptions.ImproperlyConfigured: settings.DATABASES - raise ImproperlyConfigured(“settings.DATABASES is improperly configured. ” django.core.exceptions.ImproperlyConfigured: settings.DATABASES 如何解决此错误ImproperlyConfigured:settings.DATABASES配置不正确。 请提供引擎值。 - How to solve this error ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. 带有Django 1.8的Mongoengine:配置不正确:settings.DATABASES配置不正确。 请提供引擎值 - Mongoengine with Django 1.8: ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value ImproperlyConfigured:settings.DATABASES 配置不正确。 请提供 ENGINE 值。 查看设置文档以获取更多详细信息 - ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details 配置不当:settings.DATABASES 配置不正确。 请提供 ENGINE 值 - ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value 受够了错误ImproperlyConfigured:settings.DATABASES配置不正确。 请提供引擎值 - Fed up with the error ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value settings.DATABASES 配置不正确。 请提供 ENGINE 值 - settings.DATABASES is improperly configured. Please supply the ENGINE value 安装Graphite时出现Django错误 - settings.DATABASES配置不正确。 请提供ENGINE值 - Django error when installing Graphite - settings.DATABASES is improperly configured. Please supply the ENGINE value Django - settings.DATABASES 配置不正确。 请提供 ENGINE 值 - Django - settings.DATABASES is improperly configured. Please supply the ENGINE value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM