Why am I not allowed to delete an auth user if I a...
# help
a
Why am I not allowed to delete an auth user if I am using a NULLABLE foreign key that points to that user? Should it not just turn into null? I'm getting this message:
Failed to delete user: update or delete on table "users" violates foreign key constraint "todos_user_id_fkey" on table "todos"
n
Hello @anon_123! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
g
Do you have ON DELETE SET NULL as part of the foreign key constraint?
n
schoening (2022-04-24)
a
I assumed this would be setup automatically. I did not see this option in the UI. How can I do that @garyaustin
g
Copy code
alter table todos
drop constraint todos_user_id_fkey,
add constraint todos_user_id_fkey
foreignkey (user_id)
references users
on delete set NULL;
If I got the punctuation correct and your table/columns correct.
a
Thank you @garyaustin