Reputation: 83
I want the django to connect to db2 as another user (a DBADM) instead of db2inst1, the schema is XXX. but after running python manage.py migrate
, it failed after creating tables DJANGO_MIGRATIONS and DJANGO_CONTENT_TYPE. They are both empty. The returned error is [IBM][CLI Driver][DB2/AIX64] SQL0601N The name of the object to be created is identical to the existing name "XXX.DJANGO_MIGRATIONS" of type "TABLE". SQLSTATE=42710
. I tried to drop tables and run the command again but failed. It seems it cannot find the DJANGO_MIGRATIONS table when trying to insert a new record so it tries to create it again. The command however succeeds when using db2inst1.
So I want to know if the issue is caused by insufficient user privileges? What privileges/roles the connection user should have? Are there any restrictions on the connection user? I tried to find document but couldn't find any.
Versions: Django 3.2, ibm-db-django 1.5.0.0, ibm-db 3.1.0, DB2 10.5
--Added database configuration in settings.py--
DATABASES = {
'default': {
'ENGINE': 'ibm_db_django',
'CURRENTSCHEMA': 'XXX',
'NAME': 'DBNAME',
'USER': 'myuser',
'PASSWORD': 'password',
'HOST': 'hostname',
'PORT': '50000',
'PCONNECT': True, #Optional property, default is false
}
}
Upvotes: 1
Views: 1216
Reputation: 83
The error returns due to different CURRENTSCHEMA and USER: https://github.com/ibmdb/python-ibmdb-django/issues/68
Upvotes: 0
Reputation: 12267
The immediate error (SQL0601N) is caused by a previous run of python manage.py
having begun (and possibly failed) for the same USER mentioned in the DATABASES stanza of the settings.py
.
The ibm_db_django 1.5.0.0 ignores the CURRENTSCHEMA in the settings.py
due to a coding defect, and the consequence is the symptom that you experience. For details of the defect and a code workaround, see this link.
You will also experience a second problem (unrelated to the first) because you are using Db2-LUW v10.5, which does not have full support for BOOLEAN datatype, which instead got introduced at Db2-LUW v11.1, so consider upgrading your Db2-LUW server to V11.1 or V11.5 at latest fixpack.
While it is possible to hack the supplied migrations to avoid using BOOLEAN, it is for you to decide on the sustainability of that approach.
Keep in mind that IBM ended Db2 defect support for v10.5 on 30/April/2020, (no further fixes or enhancements) so unless your company already purchased extended support, then you should upgrade your Db2-LUW server anyway. If your company refuses to upgrade, you must decide whether your choice of toolset is appropriate.
Upvotes: 1