DJango 1.8 test case fails with IntegrityError error

82 views
Skip to first unread message

Jose Paul

unread,
Sep 21, 2015, 7:14:39 AM9/21/15
to Django users
I am trying to run DJango 1.8 test cases with DB2

Several insert statement fails 

Here is the insert command generated by test case.

INSERT INTO "AUTH_USER" ("PASSWORD", "LAST_LOGIN", "IS_SUPERUSER", "USERNAME", "FIRST_NAME", "LAST_NAME", "EMAIL", "IS_STAFF", "IS_ACTIVE", "DATE_JOINED") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)

Value : (None, None, True, u'superuser', None, None, None, False, True, u'2015-09-17 12:31:09.562000')

ibm_db_dbi::IntegrityError: Statement Execute Failed: [IBM][CLI Driver][DB2/NT] SQL0407N  Assignment of a NULL value to a NOT NULL column "TBSPACEID=2, TABLEID=24, COLNO=1" is not allowed.  SQLSTATE=23502\r SQLCODE=-407


Except last_login none of the field are nullable .
But still DJango testcase generate insert statement  as above and pass None as value which fails .

Why this happens ?.
Why correct non null values are not generated for non null field .

Please help .Thanks ,
Jose

Jose Paul

unread,
Sep 21, 2015, 7:38:28 AM9/21/15
to Django users

Please see the call stack too ,for one of the error


"C:\Users\IBM_ADMIN\PythonWorkspace\DJangoTestCases\src\DJangoTestCases\tests\admin_filters\tests.py", line 229, in setUp

self.alfred = User.objects.create_user('alfred', 'alf...@example.com')

File "C:\Python27\lib\site-packages\django\contrib\auth\models.py", line 187, in create_user

**extra_fields)

File "C:\Python27\lib\site-packages\django\contrib\auth\models.py", line 182, in _create_user

user.save(using=self._db)

File "C:\Python27\lib\site-packages\django\db\models\base.py", line 710, in save

force_update=force_update, update_fields=update_fields)

File "C:\Python27\lib\site-packages\django\db\models\base.py", line 738, in save_base

updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)

File "C:\Python27\lib\site-packages\django\db\models\base.py", line 822, in _save_table

result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)

File "C:\Python27\lib\site-packages\django\db\models\base.py", line 861, in _do_insert

using=using, raw=raw)

File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 127, in manager_method

return getattr(self.get_queryset(), name)(*args, **kwargs)

File "C:\Python27\lib\site-packages\django\db\models\query.py", line 920, in _insert

return query.get_compiler(using=using).execute_sql(return_id)

File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line 974, in execute_sql

cursor.execute(sql, params)

File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 67, in execute

return self.cursor.execute(sql, params)

File "c:\python27\lib\site-packages\ibm_db_django-1.0.7-py2.7.egg\ibm_db_django\pybase.py", line 165, in execute

six.reraise(utils.IntegrityError, utils.IntegrityError( *tuple( six.PY3 and e.args or ( e._message, ) ) ), sys.exc_info()[2])

File "c:\python27\lib\site-packages\ibm_db_django-1.0.7-py2.7.egg\ibm_db_django\pybase.py", line 161, in execute

return super( DB2CursorWrapper, self ).execute( operation, parameters )

File "c:\python27\lib\site-packages\ibm_db-2.0.5.1-py2.7.egg\ibm_db_dbi.py", line 1335, in execute

self._execute_helper(parameters)

File "c:\python27\lib\site-packages\ibm_db-2.0.5.1-py2.7.egg\ibm_db_dbi.py", line 1247, in _execute_helper

raise self.messages[len(self.messages) - 1]

IntegrityError: Statement Execute Failed: [IBM][CLI Driver][DB2/NT] SQL0407N Assignment of a NULL value to a NOT NULL column "TBSPACEID=2, TABLEID=24, COLNO=5" is not allowed. SQLSTATE=23502\r SQLCODE=-407

Simon Charette

unread,
Sep 21, 2015, 11:07:51 AM9/21/15
to Django users

Jose Paul

unread,
Sep 22, 2015, 2:04:44 AM9/22/15
to Django users
Hi Simon,

I am working on this support .

But the test case generates sql with null values for non null fields.

We cannot change the model ,because this is part of python ,i believe.

The problem might be the schema generated for the table from the model .
I can see only one field as non null in DB2.

Is this different from other database?.

Thanks,
Jose
Reply all
Reply to author
Forward
0 new messages