0

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.

7
  • How do you define which tables should be in which database. Is it a static setup or somehow dynamic? Commented Dec 5, 2018 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. Commented Dec 5, 2018 at 10:48
  • It's a duplicate for multiple databases and multiple models in django Commented Dec 5, 2018 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. Commented Dec 5, 2018 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. Commented Dec 5, 2018 at 14:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.