ibmdb / python-ibmdb-django

IBM DB2 Driver for the Django application Framework
Apache License 2.0
29 stars 42 forks source link

SQL0601N The name of the object to be created is identical to the existing name "DJANGO_MIGRATIONS" of type "TABLE" #68

Closed lke27 closed 2 years ago

lke27 commented 2 years ago

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

imavo commented 2 years ago

If your settings.py uses both CURRENTSCHEMA and USER with different values then the python manage.py migrate will fail with your symptom.

Seems to be a defect caused by the current code in ibm_db_django.

The defect is that the file "pybase.py" uses mixed case CurrentSchema, but ibm_db_dbi.py searches for uppercase CURRENTSCHEMA in the dsn string.

Suggested fix to pybase.py class DatabaseWrapper method get_new_connection, change (existing line below) kwargs['dsn'] += "CurrentSchema=%s;" % ( kwargs.get( 'currentschema' )) (new line below) kwargs['dsn'] += "CURRENTSCHEMA=%s;" % ( kwargs.get( 'currentschema' ))

praveen-db2 commented 2 years ago

Hi @lke27, I am working on Django 3.2.9, will be releasing in few weeks, I will have above fix said by @imavo in this release. Until then you can manually fix and use.

praveen-db2 commented 2 years ago

Fix given in version 1.5.1.0