我有两个django应用,在服务器Main
上调用A
,在服务器Tasker
上调用B
。
Main
响应用户请求并执行许多可以快速完成的事情。
另一方面,Tasker
只有一些用于记录和芹菜任务的模型。
在服务器A
上,'{1}}中不包含'tasker',因为我在那里不需要它,而在服务器INSTALLED_APPS
上,它是。{/ p>
从django's documentation开始,我创建了一个路由器并定义了B
和db_for_read
db_for_write
在服务器B上,class ModelsRouter(object):
"""
Logging models are on local,
but updated models are on another server
"""
def db_for_read(self, model, **hints):
if model._meta.app_label == 'tasker':
return 'tasker'
return None
def db_for_write(self, model, **hints):
if model._meta.app_label == 'tasker':
return 'tasker'
return None
设置包含两个键:
DATABASES
指向服务器A default
指向localhost 我遇到的问题是,当我运行tasker
时,manage.py migrate
的模型是在服务器A上创建的。
如何在服务器B上设置项目以了解以下内容:
- tasker
app的模型在服务器A上
- main
的模型在服务器B上(也是本地主机)?
答案 0 :(得分:0)
我设法通过以下方式解决问题:
main
tasker
数据库配置
tasker
的服务器上,我修改了DATABASES
,以便default
指向localhost
,main
指向其他服务器main
1}}居住在服务器B上,我运行manage.py migrate tasker
,因为该数据库中不需要其他模型。
它现在正在运作:
运行manage.py migrate tasker
时遇到的问题是:
RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.
但我会管理它。