mazzini
September 9, 2025, 8:46am
1
Hello,
I’m trying to upgrade our self hosted instance from 2.025.29a to 2.025.34a but Kobocat migrations failed on step logger.0044_alter_attachment_to_remove_null_values with the error “django.db.utils.IntegrityError: column “user_id” of relation “logger_attachment” contains null values".
How can I solve this issue ?
Best regards,
Fred
pruzige
September 9, 2025, 10:17am
2
Am not expert , but bellow is according to AI Assistance::::
Why this happens
In KoboCAT’s logger app, the Attachment.user field used to allow nulls.
Newer versions changed the model so user is required .
If you already have attachments created without a linked user, the migration cannot enforce the constraint until those rows are fixed.
How to fix it
You need to update those rows before re-running migrations:
1. Enter your KoboCAT DB (PostgreSQL)
sudo -u postgres psql kobocat
(or whichever DB name you’re using for KoboCAT)
2. Inspect problematic rows
SELECT id, user_id, instance_id, filename
FROM logger_attachment
WHERE user_id IS NULL
LIMIT 20;
This shows which attachments have missing users.
3. Decide how to fix
Options:
Safe default : Set them to the superuser or a “system” account.
First find a valid user ID:
SELECT id, username FROM auth_user;
Remove orphaned rows : If you don’t need them (rarely recommended).
4. Apply update
For example, if your superuser has id=1:
UPDATE logger_attachment
SET user_id = 1
WHERE user_id IS NULL;
5. Exit PostgreSQL and re-run migrations
python3 manage.py migrate
pruzige
September 10, 2025, 5:13pm
4
You are welcome.
I hope it went well