python - Django adds square Brackets in querying sql server -
i trying connect azure sql service django on mac osx. when following
from photo_mapper.models import restaurant rest_query = restaurant.objects.all().query print rest_query select [ate_it.restaurant].[id], [ate_it.restaurant].[name], [ate_it.restaurant].[area], [ate_it.restaurant].[city], [ate_it.restaurant].[submitter], [ate_it.restaurant].[pending], [ate_it.restaurant].[zid] [ate_it.restaurant]
due when restaurant.objects.all()
traceback (most recent call last): file "<console>", line 1, in <module> file "/users/anubhav/workspace/ate-it/venv/lib/python2.7/site-packages/django/db/models/query.py", line 234, in __repr__ data = list(self[:repr_output_size + 1]) file "/users/anubhav/workspace/ate-it/venv/lib/python2.7/site-packages/django/db/models/query.py", line 258, in __iter__ self._fetch_all() file "/users/anubhav/workspace/ate-it/venv/lib/python2.7/site-packages/django/db/models/query.py", line 1074, in _fetch_all self._result_cache = list(self.iterator()) file "/users/anubhav/workspace/ate-it/venv/lib/python2.7/site-packages/django/db/models/query.py", line 52, in __iter__ results = compiler.execute_sql() file "/users/anubhav/workspace/ate-it/venv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 848, in execute_sql cursor.execute(sql, params) file "/users/anubhav/workspace/ate-it/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute return super(cursordebugwrapper, self).execute(sql, params) file "/users/anubhav/workspace/ate-it/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) file "/users/anubhav/workspace/ate-it/venv/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) file "/users/anubhav/workspace/ate-it/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) file "/users/anubhav/workspace/ate-it/venv/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 538, in execute return self.cursor.execute(sql, params) programmingerror: ('42s02', "[42s02] [freetds][sql server]invalid object name 'ate_it.restaurant'. (208) (sqlexecdirectw)")
however when manually run query select * ate_it.restaurant
using django.db.connections
runs fine. can prevent django adding square brackets.
my database settings are
databases = { 'default': { 'engine': 'sql_server.pyodbc', 'name': 'mydatabase', 'user' : 'myuser', 'password' : 'mypwd', 'host' : 'myserver', 'port' : '1433', } }
i followed this link freetds , unixodbc setup
this because of pyodbc. generates quoted name of table, index or column. modify function quote_name in pyodbc/operations.py change line
return '[%s]' % name
return name
Comments
Post a Comment