2013-01-23 1 views
0

'다중 데이터베이스를 사용 해요, 나는 시도 :어떻게 다중 데이터베이스를 사용하여 장고에서 select를 할 수 있습니까? 내가

 cursor = connection.cursor().using(profile.dbname) 
     cursor.execute('select id_retorno from prc_sequenciadora(' + str(profile.idempresa) + ', "VENDA_PEDIDO", "IDVENDA_PEDIDO", 0, 0)')# calls PROCEDURE named LOG_MESSAGE which resides in MY_UTIL Package 
     cursor.fetchall() 

그러나이 오류가 나타납니다/comerx/pedidos/노보/ 에서

AttributeError'커서 사용 ''오브젝트가 속성이 없습니다 ' 여기

는 역 추적입니다 : 모든

답변

1

처음에 http://pastebin.com/CD7B8BxJ

감사합니다, 당신 django.db.connections를 임포트해야한다. django.db.connections는 별칭으로 특정 데이터베이스 연결을 검색 할 수있는 사전 형 객체이다. 그런 다음 적절한 커서를 사용해야합니다. Cursor 객체에는 "using"메서드가 없다고 생각합니다 (즉, 오류 메시지가 말하는 것입니다).

그래서, 우리가 가진 :

from django.db import connections 
my_db_alias = profile.dbname #in your situation 
cursor = connections[my_db_alias].cursor() 
# Your code goes here... 

자세한 내용은 : https://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly

+0

감사합니다, 잘 작동! –

관련 문제