0

I am trying to access one Django Project Database value from another Django Project. So far I have tried making REST API on both the applications and it is working somewhat well on the local server. However, I am concerned that when I will be deploying both the projects on the server it will create some lag to access over the API. Moreover, if one server/application is down for maintenance, the other will be inaccessible.

Is it possible to directly access the other app database without using API as it will be much more faster and reliable?

Thanks.

QuentinC
  • 12,311
  • 4
  • 24
  • 37
Mehadi
  • 85
  • 8
  • Hi, i do not understand what do you mean by calling dbs of "django project database", a db it's just a db, just access they directly using database routers as here: https://docs.djangoproject.com/en/4.0/topics/db/multi-db/#:~:text=The%20master%20router%20is%20used%20by%20Django%E2%80%99s%20database,turn%20until%20a%20database%20suggestion%20can%20be%20found. – Luiz May 12 '22 at 10:37
  • If both the databases are under the same project then we can access them via the router by calling the models class. However, I want to call Project 2 Database in Project 1 wherein Project 1 I will use Project 2 database values and perform CRUD. How can I achieve that? Here by projects I mean two separate Django Projects / Applications – Mehadi May 13 '22 at 02:55
  • You can connect django to any database using routers, put the connection values under settings.py, create a new app in your django project, create the models (just to let django know each tables are on this db not to create the tables), and you make the database routers, it's important to not let this django app migrate in this foreign database. References: https://docs.djangoproject.com/en/4.0/topics/db/multi-db/ https://stackoverflow.com/questions/53859629/how-to-add-database-routers-to-a-django-project – Luiz May 13 '22 at 11:46

0 Answers0