I have a really weird requirement. I am working on a project where the I have to interact with two databases and each of them has different tables. One of the databases is a legacy databse and I have got the models with the help of inspectdb. The other one has to be created from scratch. To be precise, if I have table_x in db_1 then I should not create table_x in db_1. Is it possible possible in Django? Any sort of help will be highly appreciated.
Asked
Active
Viewed 349 times
0
-
How do you define which tables should be in which database. Is it a static setup or somehow dynamic? – Tim Dec 05 '18 at 10:46
-
I am not sure which DBMS you are using. You can look up psycopg for postgres and mysqldb for mysql. Using this you can use connection string to connect to the databases separately, look up tables in information_schema.tables and compare them. – Vishal Raghavan Dec 05 '18 at 10:48
-
It's a duplicate for [multiple databases and multiple models in django](https://stackoverflow.com/questions/18547468/multiple-databases-and-multiple-models-in-django) – Reza Torkaman Ahmadi Dec 05 '18 at 11:08
-
@RezaTorkamanAhmadi No. it is not. I am not dealing with migrations. The models are created from the database tables using inspectdb. All I need is to be able to read or write from two datases which have different tables. – sajid Dec 05 '18 at 14:09
-
use link that i suggested. but instead add `manage=False` to your tables. by that you will be using ORM django for better functionallity, but databases could be any where and django doesn't care about their migrations. – Reza Torkaman Ahmadi Dec 05 '18 at 14:28
-
@RezaTorkamanAhmadi Thanks for the hint. I have solved the problem. I will post the solution very soon. – sajid Dec 05 '18 at 16:17
-
anytime my friend. – Reza Torkaman Ahmadi Dec 05 '18 at 16:32