Skip to content
Advertisement

constraint c for table t does not exist on PostgreSQL even though it’s there

I’m trying to run an INSERT query on TablePlus.

Instead of the query sending a success message, I’m getting an ERROR: constraint “minutes_clone_stick_tickers_unique” for table “minutes_clone” does not exist.

Here is an image of my table structure.

to replicate:

I’ve tried many things, like removing ON CONSTRAINT and dropping and re-adding the constraing but haven’t been able to solve this issue. Any solutions?

Advertisement

Answer

You are mixing up indexes and constraints. That is understandable, because a unique constraint is always implemented by a unique index, but they are still not the same.

To make your statement work, you need a unique constraint on top of the index you currently have. You can create that with:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement