Is it possible to read separately an autoincremental key relative to another id

22 Views Asked by At

I'm developing a database similar to the Tinder database. And encountered error 1075 while creating the message table.

create table message
(
    message_chat_id BIGINT UNSIGNED,
    message_id BIGINT UNSIGNED AUTO_INCREMENT,
    message_sender INT UNSIGNED NOT NULL,
    message_message TEXT NOT NULL,
    message_timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,

    PRIMARY KEY (message_chat_id, message_id),

    CONSTRAINT cn_fk_message_to_chat
        FOREIGN KEY (message_chat_id)
        REFERENCES chat(chat_id)
          ON DELETE CASCADE,

    CONSTRAINT cn_fk_chat_message_sender_client
        FOREIGN KEY (message_sender)
        REFERENCES client(client_id)
          ON DELETE CASCADE

);

I want the message_id to be calculated anew for each new message_chat_id. Is there any way to do this and not encounter error 1075?

Or maybe it's better to just make only message_id primary and froget about previous idea?

0

There are 0 best solutions below