google-code-export / django-pyodbc

Automatically exported from code.google.com/p/django-pyodbc
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Insert into Nullable DateTimeField failed #106

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a model field with models.DateTimeField(null = True, blank = True)
2. Pass None as a value for this field
3. it failed on .save() (see the traceback below)

What is the expected output? What do you see instead?
NULL value should be inserted.

What version of the product are you using? On what operating system?

Django: 1.3.0 final
Python: Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit 
(Intel)] on win32
Windows: Windows 7 Professional SP1
SQL Server: SQL Server 2005
pyodbc: pyodbc-2.1.7-py2.6
django-pyodbc: recent trunk

Please provide any additional information below.

Traceback (most recent call last):
  File "C:\Test\test_insert.py", line 65, in <module>
    lead.save()
  File "C:\Python26\lib\site-packages\django\db\models\base.py", line 460, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "C:\Python26\lib\site-packages\django\db\models\base.py", line 553, in save_base
    result = manager._insert(values, return_id=update_pk, using=using)
  File "C:\Python26\lib\site-packages\django\db\models\manager.py", line 195, in _insert
    return insert_query(self.model, values, **kwargs)
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line 1436, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py", line 791, in execute_sql
    cursor = super(SQLInsertCompiler, self).execute_sql(None)
  File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py", line 735, in execute_sql
    cursor.execute(sql, params)
  File "C:\Python26\lib\site-packages\django\db\backends\util.py", line 34, in execute
    return self.cursor.execute(sql, params)
  File "C:\Python26\lib\site-packages\sql_server\pyodbc\base.py", line 318, in execute
    return self.cursor.execute(sql, params)
pyodbc.Error: ('07009', '[07009] [Microsoft][SQL Native Client]Invalid 
Descriptor Index (0) (SQLDescribeParam); [07009]
[Microsoft][SQL Native Client]Invalid parameter number (0)')

Original issue reported on code.google.com by nbma...@gmail.com on 20 Jun 2011 at 2:34

GoogleCodeExporter commented 9 years ago
To reproduce the problem:

#models.py
class MyModel(models.Model):
    date_nullable = models.DateTimeField(null = True, blank = True)

#test.py
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from myapp.models import MyModel

mymodel = MyModel(
    pk = 123,
    date_nullable = None
)
mymodel.save()

Original comment by nbma...@gmail.com on 20 Jun 2011 at 2:57

GoogleCodeExporter commented 9 years ago
Was there any workaround for this?  I'm hitting it (I think) during a manage.py 
loaddata call with a JSON fixture.  It came straight from another Django 
instance using SQL Server, so I expected it to just work...

Original comment by m...@subfocal.net on 7 Jul 2012 at 4:12