문제

I have a django site and I need to access data from another database which is in another host. how do I connect it and even if i connect, how do I access that table from this database, without having the table's data in the models.py? Please help me

도움이 되었습니까?

해결책

If you want to use the Django ORM, you can use Django's built-in multi-database support. To create the models.py file, you can use the inspectdb management command.

If you don't need the ORM, you can connect still specify the additional database in your settings, but only perform raw SQL queries. You need to get the right connection for your additional database:

from django.db import connections
cursor = connections['my_db_alias'].cursor()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top