Foreign key relation: New Action if referenced is not present in table #19929
Unanswered
tizum
asked this question in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I'm creating a WhatsApp campaign system using the official API, and when someone replies to a message, I always receive the message/context ID in the payload. I save this information directly in the 'contact_replys' table without checking beforehand if the message/context ID exists in the 'campaign_messages' table.
I don't check because I save all received messages in this table, and it would be too many requests, you see?
The problem is that when I try to create a new row with the response in the 'contact_replys' table, it throws an error because the 'message_id' doesn't exist in the 'campaign_messages' table.
The suggestion would be to add a new verification, similar to 'Action if referenced row is updated' and 'Action if referenced row is removed.'
This would allow setting the column to a null value automatically because it doesn't make sense to save the 'message_id' with the response if it's not associated with a campaign.
Below, I'll leave where the suggestion option should be, along with the error log when I try to insert the row.
{ "status": 409, "error": { "code": "23503", "message": "insert or update on table \"contact_replys\" violates foreign key constraint \"contact_replys_message_id_fkey\"", "details": "Key (message_id)=(wamid.HBgNNTUyMTk4NTA3MjYyNxUCABEYEkQ2NUMxMjRCNzc2NENCMTVGOQA=) is not present in table \"campaigns_messages\".", "hint": null } }All reactions