我的代码可以访问 3 个数据库。syncdb 必须在两个数据库中创建所有模型表。我不确定如何做到这一点。以下不起作用。
DATABASES = {
'default': {}, # empty. default is required
'db_1': { # want tables created in this
...
},
'db_2': { # want tables created in this
...
},
'other': { # do NOT want tables created in this
...
},
}
路由器:(一个单独的路由器处理身份验证表)
import random
class OtherRouter(object):
def db_for_read(self, model, **hints):
return random.choice(['db_1', 'db_2'])
def db_for_write(self, model, **hints):
return "db_1"
def allow_relation(self, obj1, obj2, **hints):
return True
def allow_syncdb(self, db, model):
db_list = ('db_1', 'db_2')
if db in db_list:
return True
return None