In my current project I am creating a very simple 1-to-1 messaging service. I have two tables, users
and messages
. The current structure of the messages
table is like this:
id | from | to | message | sent | received
int | int | int | string | datetime | datetime
The from
and to
fields are both foreign keys to the users
primary key (id). That seems to work fine but I cannot make them both use cascading deletes. I get this error:
Introducing FOREIGN KEY constraint 'FK_messages_users_to' on table
'messages' may cause cycles or multiple cascade paths. Specify ON
DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint. See previous errors.
Can this be done? I don't see why it doesn't work. If a user was deleted I want to delete the entire conversation so any rows that have the users id in either the from
or the to
field.