Thanks to visit codestin.com
Credit goes to github.com

Skip to content

The column named "PSUDO_USERNAME" cannot be a column of a primary key or unique key constraint because it can contain null values. #103

@boc-tdunn

Description

@boc-tdunn

On a brand new project start I install Django, ibm_db, ibm_db_django. I configure DB like so:

DATABASES = {
    'default': {
        'ENGINE': 'ibm_db_django',
        'NAME': 'TEST',
        'USER': '<redacted>',
        'PASSWORD': '<redacted>',
        'HOST': 'localhost',
        'PORT': '25000',
        'PCONNECT': True,
        'OPTIONS': {
            'options': '-c search_path=BOROLIB'
        }
    },
}

Then run:

python.exe .\manage.py makemigrations
python.exe .\manage.py migrate

Which results in this error:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying auth.0008_alter_user_username_max_length...Traceback (most recent call last):
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_dbi.py", line 1312, in _execute_helper
    return_value = ibm_db.execute(self.stmt_handler, parameters)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception: Statement Execute Failed: [IBM][CLI Driver][DB2/NT64] SQL0542N  The column named "PSUDO_USERNAME" cannot be a column of a primary key or unique key constraint because it can contain null values.  SQLSTATE=42831  SQLCODE=-542

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_django\pybase.py", line 314, in execute
    super( DB2CursorWrapper, self ).execute( operation, parameters )
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_dbi.py", line 1409, in execute
    self._execute_helper(parameters)
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_dbi.py", line 1322, in _execute_helper
    raise self.messages[len(self.messages) - 1]
ibm_db_dbi.ProgrammingError: ibm_db_dbi::ProgrammingError: Statement Execute Failed: [IBM][CLI Driver][DB2/NT64] SQL0542N  The column named "PSUDO_USERNAME" cannot be a column of a primary key or unique key constraint because it can contain null values.  SQLSTATE=42831  SQLCODE=-542

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\tdunn\Documents\workspaces\test\manage.py", line 22, in <module>
    main()
  File "C:\Users\tdunn\Documents\workspaces\test\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\core\management\base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\core\management\base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\core\management\base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\core\management\commands\migrate.py", line 357, in handle
    post_migrate_state = executor.migrate(
                         ^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\db\migrations\executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\db\migrations\executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
            ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\db\migrations\executor.py", line 255, in apply_migration
    state = migration.apply(state, schema_editor)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\db\migrations\migration.py", line 132, in apply
    operation.database_forwards(
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\db\migrations\operations\fields.py", line 241, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_django\schemaEditor.py", line 287, in alter_field
    self._alter_field(model, old_field, new_field, old_type, new_type,
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_django\schemaEditor.py", line 413, in _alter_field
    old_field, new_field = self.alterFieldDataTypeByRemaking(model, old_field, new_field, strict)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_django\schemaEditor.py", line 819, in alterFieldDataTypeByRemaking
    _ , skip_post = self.add_field_pre(model, tmp_new_field, unique)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_django\schemaEditor.py", line 682, in add_field_pre
    self.execute(sql, params)
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\db\backends\base\schema.py", line 202, in execute
    cursor.execute(sql, params)
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\db\backends\utils.py", line 122, in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\db\backends\utils.py", line 79, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\db\backends\utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_django\pybase.py", line 323, in execute
    six.reraise(utils.ProgrammingError, utils.ProgrammingError( *tuple( six.PY3 and e.args or ( e._message, ) ) ), sys.exc_info()[2])
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\six.py", line 718, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_django\pybase.py", line 314, in execute
    super( DB2CursorWrapper, self ).execute( operation, parameters )
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_dbi.py", line 1409, in execute
    self._execute_helper(parameters)
  File "C:\Users\tdunn\Documents\workspaces\test\.venv\Lib\site-packages\ibm_db_dbi.py", line 1322, in _execute_helper
    raise self.messages[len(self.messages) - 1]
django.db.utils.ProgrammingError: Statement Execute Failed: [IBM][CLI Driver][DB2/NT64] SQL0542N  The column named "PSUDO_USERNAME" cannot be a column of a primary key or unique key constraint because it can contain null values.  SQLSTATE=42831  SQLCODE=-542

This is an out-of-the-box django with only a db connection configuration. I'm not sure how to fix this or proceed.

Versions:
Django==5.1.1
ibm_db==3.2.3
ibm_db_django==1.5.3.0
Python 3.12.3
DB2/NT64 11.5.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions