The django project has multiple apps and they all right now access the same DB. If I want one app which has only read queries to read from read replica will I have to add routers for both DB or creating one router for read replica and alloting it to the app will work? Is there a better way to do this?
Asked
Active
Viewed 162 times
2
-
I want to use the replica for an entire app for all the operations, while other apps keep using the default db., which is not looking possible through routers. – Sarwar May 17 '19 at 09:04
1 Answers
-1
you can use multiple database as defined in documentation: https://docs.djangoproject.com/en/2.0/topics/db/multi-db/
Ex:
DATABASES = {
'default': {
'NAME': 'user_data',
'ENGINE': 'django.db.backends.mysql',
'USER': 'mysql_user',
'PASSWORD': 'password1'
},
'read_replica': {
'NAME': 'customer_data',
'ENGINE': 'django.db.backends.mysql',
'USER': 'mysql_cust',
'PASSWORD': 'password2'
}
}
After use a Database Router (django.db.router): https://docs.djangoproject.com/en/2.0/topics/db/multi-db/#using-routers There is a DATABASE_ROUTERS config as well.

Dharmesh Fumakiya
- 2,276
- 2
- 11
- 17
-
Please read the question. I want to use the replica for an entire app for all the operations, while other apps keep using the default db., which is not looking possible through routers. – Sarwar May 17 '19 at 09:04