way to handle a self referencing foreign key? By that I mean a parent/child relationship within the same table. As an example, I have this:
CREATE TABLE chats(
id BIGSERIAL PRIMARY KEY,
type TEXT,
title TEXT,
username TEXT,
first_name TEXT,
last_name TEXT,
description TEXT,
created_at TIMESTAMP,
updated_at TIMESTAMP,
log_channel_id BIGSERIAL,
FOREIGN KEY (log_channel_id) REFERENCES chats(id) ON DELETE CASCADE ON UPDATE CASCADE
);
but the log_channel_id gives me issues when I try to create the chat initially because it's NULL, and somehow that seems to violate the foreign key constraint.
Cannot set the field as NULL?
Обсуждают сегодня