[英]django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. router.py given
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']
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.