© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
3 replies
Sarcodo

No unique constraint error when creating table

I'm trying to create a new table which links to one of my other tables however when trying to create the new table I get an error: "Failed to run sql query: there is no unique constraint matching given keys for referenced table". I looked up a bit and it seems that this error is caused when trying to create a foreign key on columns that aren't unique or a PK.

My tables look like this:
Table_1:
routine_id PK
exercise_id PK
created_at

Table_2: (The one I'm trying to create)
routine_id PK -> reference to Table_1.routine_id
exercise_id PK -> reference to Table_2.exercise_id
workout_id FK
...some other columns that aren't FKS
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

no unique constraint matching
SupabaseSSupabase / help-and-questions
4y ago
Getting - there is no unique constraint matching
SupabaseSSupabase / help-and-questions
4y ago
Constraint unique where other column
SupabaseSSupabase / help-and-questions
7mo ago
duplicate key value violates unique constraint "profiles_pkey"
SupabaseSSupabase / help-and-questions
3y ago