Fix · Supabase and databases
violates foreign key constraint (23503)
What you may see
- Saving or deleting fails with a message about a key not present or still referenced
Most likely cause
The row points to another row that does not exist, or you delete a row that others still point to.
Check first (about two minutes)
- Read the table and key names in the message.
The fix prompt
What you type here never leaves your browser. The search runs on this page, and nothing is sent to a server or to an AI.
Kept only in this browser, on this device. Keys and passwords are removed before anything is saved.
Prompt language
Paste it into Claude, ChatGPT, Gemini or Cursor, then follow what it says.
After you tried it, did it work?
Steps
- Show which row or id the message mentions and whether it exists.
- For a missing parent: create the parent first or fix the id. For a delete: decide with me whether to archive (a deleted flag), delete the children first, or block the delete.
Do not do this
- Do not cascade-delete orders or customers without a backup.
- Do not drop the foreign key to make the error go away.