Discourse higher 3.2.0 (v3.3.3,…).
Sto usando PostgreSQL 15.3 (EnterpriseDB Advanced Server 15.3.0) su x86_64-pc-linux-gnu, compilato da gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-16), a 64 bit.
Quando eseguo rake db:migrate, incontro questo errore:
PG::NotNullViolation: ERRORE: valore null nella colonna "first_unread_at" della relazione "user_stats" viola il vincolo not-null (PG::NotNullViolation)
DETAIL: La riga fallita contiene (130, 0, 0, 0, 0, 0, 0, 2025-02-25 03:27:48.934913, null, null, 0, 0, 0, null, 0, 0, 0, null, 0, null, null, null, 0, 0)
Ho investigato e ho scoperto che il motivo è che l’applicazione sta cercando di inserire un valore null in un campo che non è null con un default current_timestamp.
La mia soluzione:
BEGIN;
ALTER TABLE user_stats
ALTER COLUMN first_unread_at SET NOT NULL,
ALTER COLUMN first_unread_at SET DEFAULT NOW();
COMMIT;
BEGIN;
ALTER TABLE user_stats
ALTER COLUMN first_unread_pm_at SET NOT NULL,
ALTER COLUMN first_unread_pm_at SET DEFAULT NOW();
COMMIT;
BEGIN;
ALTER TABLE group_users
ALTER COLUMN first_unread_pm_at SET NOT NULL,
ALTER COLUMN first_unread_pm_at SET DEFAULT NOW();
COMMIT;
Ma ci sono molti altri campi che non possono essere inseriti, non sono riuscito a trovarli e correggerli tutti usando questo metodo.