Traceback (most recent call last):
File "c:\python36\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "c:\python36\lib\site-packages\sql_server\pyodbc\base.py", line 547, in execute
return self.cursor.execute(sql, params)
pyodbc.DataError: ('String data, right truncation: length 22 buffer 20', '22001')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "", line 1, in
File "c:\python36\lib\site-packages\django\db\models\base.py", line 808, in save
force_update=force_update, update_fields=update_fields)
File "c:\python36\lib\site-packages\django\db\models\base.py", line 838, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "c:\python36\lib\site-packages\django\db\models\base.py", line 924, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "c:\python36\lib\site-packages\django\db\models\base.py", line 963, in _do_insert
using=using, raw=raw)
File "c:\python36\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "c:\python36\lib\site-packages\django\db\models\query.py", line 1076, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "c:\python36\lib\site-packages\django\db\models\sql\compiler.py", line 1112, in execute_sql
cursor.execute(sql, params)
File "c:\python36\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "c:\python36\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "c:\python36\lib\site-packages\django\db\utils.py", line 94, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "c:\python36\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "c:\python36\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "c:\python36\lib\site-packages\sql_server\pyodbc\base.py", line 547, in execute
return self.cursor.execute(sql, params)
django.db.utils.DataError: ('String data, right truncation: length 22 buffer 20', '22001')
The only inference I seem to be able to make from this is that I need to increase max_digits. However, I do not understand why, the above is 10 digits including the decimal places. The string error is pretty confusing, as there are no strings involved. Maybe pyodbc or django-pyodbc-azure is converting this decimal to a very long string, but I haven't been able to catch it doing that with SQL profiler since the error occurs at binding rather than execution.
This is a confusing error I'm trying to figure out. Here's the basic setup:
System
Model definition
Data Insertion
Error
Alternative Data Insertion
(no error)
(same error)
(no error)
I made a little tweak to base.py in django-pyodbc-azure to help with debugging, printing repr(sql) and repr(params) in execute.
sql & params for the error condition:
sql & params for a close, non-error condition:
Since I've been burned with decimal.Decimal and MSSQL before:
The only inference I seem to be able to make from this is that I need to increase max_digits. However, I do not understand why, the above is 10 digits including the decimal places. The string error is pretty confusing, as there are no strings involved. Maybe pyodbc or django-pyodbc-azure is converting this decimal to a very long string, but I haven't been able to catch it doing that with SQL profiler since the error occurs at binding rather than execution.