Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i access different database in django than other default database

I have the database backup script in python which inserts some data in mysql database .

Now my Django is in different database.

How can i access different database because i don't have any objects in Models.py. i want to display some data in django interface

like image 564
Mirage Avatar asked Dec 08 '25 20:12

Mirage


1 Answers

Yes, you can setup multiple database and access every one of them. you can get the specified database connection cursor using this:

from django.db import connections
cursor = connections['my_db_alias'].cursor()

where my_db_alias is your another db alias .

check the doc:

https://docs.djangoproject.com/en/1.3/topics/db/multi-db/

like image 75
MBarsi Avatar answered Dec 11 '25 09:12

MBarsi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!