How to pass 'using' DB to the django connection object

后端 未结 1 1477
终归单人心
终归单人心 2021-01-25 10:19

To query a specific database in django I can do:

Item.objects.using(\'specific_db\').all()

Is there a way to do the same using a django connect

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-25 11:02

    According the the django documentation on Using raw SQL on multiple databases, you would use connections rather than connection:

    from django.db import connections
    cursor = connections['specific_db'].cursor()
    cursor.execute("select * from item")
    

    0 讨论(0)
提交回复
热议问题