-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The column named "PSUDO_USERNAME" cannot be a column of a primary key or unique key constraint because it can contain null values. #103
Comments
After examining the default django tables that were created up until the failure. Only AUTH_USER has a username field.
... but username is not allowed to be null according to the describe table output. Looking at DJANGO_MIGRATIONS shows the last migration to complete was 0007_alter_validators_add_error_messages. Looking at the next one to run would be 0008_alter_user_username_max_length.py:
It doesn't appear to alter whether nulls are allowed for the username column. |
What's interesting here is that these migration files (the default ones included with django) only seem to be modifying the length of the underlying varchar column. If I modify the migration files directly such as to not change the field length in 0008_alter_user_username_max_length.py and 0010_alter_group_name_max_length.py such that it matches the original length, a no-op, then re-run the migration everything works. Then I undo the changes to the migration files and manually issue |
Any updates? Please let me know if I can clarify or help in anyway. |
@boc-tdunn error suggests that column PSUDO_USERNAME defined in migration file has option "null=true". Below are few examples I am giving with fix I had given,
Example 2:
Example 3:
Example 4:
Example 5:
|
Hi Praveen, Thanks for having a look! These are the default models that come with a fresh Django install - I haven't modified them. Additionally I'm not seeing anything that makes the field is nullable.
The only thing the migration files are changing with respect to this field is its length. Check out my previous comment:
So I don't know why a length change is somehow being interpreted as changing the nullability. |
@boc-tdunn do you know query for this error ? Can you paste complete query here. |
So starting with a fresh project I need to run |
How about this?
Yields:
It looks like its failing to even generate the sql statements. |
@boc-tdunn our ibm_db_django supports until Django v 4.2. I see you are using Django 5.1.1. Try using "--print-sql" option. |
@boc-tdunn if you can debug, put a break point at ibm_db_dbi.py where error is thrown and see whats sql query passed. |
I still don't see On Django 4.2 the output is: --
-- Alter field username on user
--
ALTER TABLE "AUTH_USER" ADD COLUMN "PSUDO_USERNAME" VARCHAR(150);
UPDATE "AUTH_USER" set "PSUDO_USERNAME"="USERNAME";
ALTER TABLE "AUTH_USER" ALTER COLUMN "PSUDO_USERNAME" SET NOT NULL;
ALTER TABLE "AUTH_USER" ADD CONSTRAINT auth_user_psudo_username_f526afb1_uniq UNIQUE ("PSUDO_USERNAME");
ALTER TABLE "AUTH_USER" DROP COLUMN "USERNAME" CASCADE;
ALTER TABLE "AUTH_USER" RENAME COLUMN "PSUDO_USERNAME" TO "USERNAME"; On Django 5:
So, this does appear to only be an issue with Django 5+. That said, once I got past this issue using the workaround I described here this library seemed to work ok in Django 5. Do you know when in 2025 Django5 support will be completed? It looks like support for django 4.2 will end April of 2026. |
@boc-tdunn Supporting Django 5.0 is in our yr 2025 pipeline. Second half you can expect release. |
On a brand new project start I install Django, ibm_db, ibm_db_django. I configure DB like so:
Then run:
Which results in this error:
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
The text was updated successfully, but these errors were encountered: