© 2026 Hedgehog Software, LLC

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

Cannot create public.users

Hello, I'm trying to create a public table that contains few columns from auth.users, I do not understand this SQL error and supabase AI cannot debug it :
CREATE TABLE public.users (
    id uuid PRIMARY KEY,
    user_id uuid REFERENCES auth.users (id) UNIQUE,
    email text REFERENCES auth.users (email) UNIQUE,
    created_at timestamp with time zone REFERENCES auth.users (created_at),
    updated_at timestamp with time zone REFERENCES auth.users (updated_at)
);

ERROR:  42830: there is no unique constraint matching given keys for referenced table "users"
CREATE TABLE public.users (
    id uuid PRIMARY KEY,
    user_id uuid REFERENCES auth.users (id) UNIQUE,
    email text REFERENCES auth.users (email) UNIQUE,
    created_at timestamp with time zone REFERENCES auth.users (created_at),
    updated_at timestamp with time zone REFERENCES auth.users (updated_at)
);

ERROR:  42830: there is no unique constraint matching given keys for referenced table "users"

How to solve it ?
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

Cannot create new users — auth.users.id default missing and cannot be altered
SupabaseSSupabase / help-and-questions
4mo ago
relation "public.users" does not exist
SupabaseSSupabase / help-and-questions
3y ago
Create projects for users?
SupabaseSSupabase / help-and-questions
4y ago
Create function for RLS that cannot be called by users
SupabaseSSupabase / help-and-questions
4y ago