My project is am using Multiple Data Base to manage the Auth , content type information and Project App.
我的项目是使用多个数据库来管理Auth、content type信息和项目App。
My Database Settings :
我的数据库设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test_default',
'USER': 'root',
'PASSWORD': 'root',
'PORT': '',
},
'auth_db': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test_auth_db',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '',
'PORT': '',
}
I have a router to manage for read and write
我有一个路由器来管理读写
def db_for_read(self, model, **hints):
if model._meta.app_label == "auth" or model._meta.app_label == "sessions" or model._meta.app_label == "contenttypes":
return "auth_db"
return None
def db_for_write(self, model, **hints):
if model._meta.app_label == "auth" or model._meta.app_label == "sessions" or model._meta.app_label == "contenttypes":
return "auth_db"
return None
def allow_syncdb(self, db, model):
return True
When ever i do syncdb all app content types are get updated in "auth_db". I want to stop this and sync with "default" database. So that all table will create and update only in the default DB.
当我进行syncdb时,所有的应用程序内容类型都会在“auth_db”中更新。我想停止这个并与“默认”数据库同步。因此,所有表只在默认的DB中创建和更新。
When the Project run it will use read and write based on the router config.
当项目运行时,它将使用基于路由器配置的读写。
How can i do that ?
我怎么做呢?
1 个解决方案
#1
1
I Fixed it by Updating the write funcfion
我通过更新写函数来修正它
def db_for_write(self, model, **hints):
if model._meta.app_label in ("sessions",) :
return "auth_db"
return "default"
So the the syncdb will not write any data to the "auth" and "contenttypes"
所以syncdb不会向"auth"和"contenttypes"写入任何数据
#1
1
I Fixed it by Updating the write funcfion
我通过更新写函数来修正它
def db_for_write(self, model, **hints):
if model._meta.app_label in ("sessions",) :
return "auth_db"
return "default"
So the the syncdb will not write any data to the "auth" and "contenttypes"
所以syncdb不会向"auth"和"contenttypes"写入任何数据