[{"data":1,"prerenderedAt":624},["ShallowReactive",2],{"blog-post-/blog/supabase-database-error-saving-new-user/":3},{"id":4,"title":5,"body":6,"description":597,"extension":598,"meta":599,"navigation":204,"path":619,"seo":620,"sitemap":621,"stem":622,"__hash__":623},"content/blog/supabase-database-error-saving-new-user.md","relation public.profiles does not exist - Supabase Error Fix",{"type":7,"value":8,"toc":580},"minimark",[9,14,22,38,43,46,76,79,84,95,99,102,121,124,128,138,142,224,228,231,236,245,249,258,261,265,272,405,409,412,423,427,430,440,444,477,481,506,510,513,535,538,541,544,548,573,576],[10,11,13],"h1",{"id":12},"troubleshooting-the-database-error-saving-new-user-in-supabase","Troubleshooting the \"Database error saving new user\" in Supabase",[15,16,17],"p",{},[18,19],"img",{"alt":20,"src":21},"Supabase error fix cover","/img/supabase/supabase.png",[15,23,24,25,29,30,33,34,37],{},"Discover how to troubleshoot the ",[26,27,28],"strong",{},"'Database error saving new user'",", ",[26,31,32],{},"'Failed to invite user: failed to make invite request: Database error saving new user'"," or ",[26,35,36],{},"'relation public.profiles does not exist supabase'"," error in Supabase. Our step-by-step guide helps you pinpoint the issue, review SQL code, and resolve conflicts. Perfect for developers looking to overcome this common challenge.",[39,40,42],"h2",{"id":41},"step-1-review-supabase-logs","Step 1: Review Supabase Logs",[15,44,45],{},"To identify the cause of the error in Supabase, follow these steps:",[47,48,49,53,60,67,73],"ol",{},[50,51,52],"li",{},"Log in to your Supabase account.",[50,54,55,56,59],{},"Access the ",[26,57,58],{},"\"Logs\""," section.",[50,61,62,63,66],{},"Click on the ",[26,64,65],{},"\"Auth\""," category.",[50,68,69,70],{},"In the \"Auth\" logs, filter by ",[26,71,72],{},"\"severity.\"",[50,74,75],{},"Look for the error message related to the missing relation.",[15,77,78],{},"This step will help you pinpoint the specific error message and its context.",[80,81,83],"h3",{"id":82},"common-error-message","Common Error Message:",[85,86,91],"pre",{"className":87,"code":89,"language":90},[88],"language-text","Error: 'relation public.profiles does not exist'\n","text",[92,93,89],"code",{"__ignoreMap":94},"",[39,96,98],{"id":97},"step-2-examine-sql-editor","Step 2: Examine SQL Editor",[15,100,101],{},"Inspect your SQL code in the Supabase SQL editor to ensure your User Manager Starter code or any related queries for creating the \"profiles\" table are correct:",[47,103,104,111,118],{},[50,105,106,107,110],{},"Open the ",[26,108,109],{},"SQL editor"," in Supabase.",[50,112,113,114,117],{},"Execute the SQL code responsible for creating the ",[26,115,116],{},"\"profiles\""," table.",[50,119,120],{},"Check for any warnings or errors.",[15,122,123],{},"If there are issues in your SQL code, this step will help you identify and address them.",[39,125,127],{"id":126},"step-3-delete-problematic-functions","Step 3: Delete Problematic Functions",[15,129,130,131,33,134,137],{},"In certain cases, functions or triggers might conflict with your database setup. If you've identified issues related to functions like ",[92,132,133],{},"handle_new_user",[92,135,136],{},"create trigger on_auth_user_created",", consider deleting them:",[80,139,141],{"id":140},"original-function-and-trigger","Original Function and Trigger:",[85,143,147],{"className":144,"code":145,"language":146,"meta":94,"style":94},"language-sql shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","create function public.handle_new_user()\nreturns trigger as $$\nbegin\n  insert into public.profiles (id, full_name, avatar_url)\n  values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');\n  return new;\nend;\n$$ language plpgsql security definer;\n\ncreate trigger on_auth_user_created\n  after insert on auth.users\n  for each row execute procedure public.handle_new_user();\n","sql",[92,148,149,157,163,169,175,181,187,193,199,206,212,218],{"__ignoreMap":94},[150,151,154],"span",{"class":152,"line":153},"line",1,[150,155,156],{},"create function public.handle_new_user()\n",[150,158,160],{"class":152,"line":159},2,[150,161,162],{},"returns trigger as $$\n",[150,164,166],{"class":152,"line":165},3,[150,167,168],{},"begin\n",[150,170,172],{"class":152,"line":171},4,[150,173,174],{},"  insert into public.profiles (id, full_name, avatar_url)\n",[150,176,178],{"class":152,"line":177},5,[150,179,180],{},"  values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');\n",[150,182,184],{"class":152,"line":183},6,[150,185,186],{},"  return new;\n",[150,188,190],{"class":152,"line":189},7,[150,191,192],{},"end;\n",[150,194,196],{"class":152,"line":195},8,[150,197,198],{},"$$ language plpgsql security definer;\n",[150,200,202],{"class":152,"line":201},9,[150,203,205],{"emptyLinePlaceholder":204},true,"\n",[150,207,209],{"class":152,"line":208},10,[150,210,211],{},"create trigger on_auth_user_created\n",[150,213,215],{"class":152,"line":214},11,[150,216,217],{},"  after insert on auth.users\n",[150,219,221],{"class":152,"line":220},12,[150,222,223],{},"  for each row execute procedure public.handle_new_user();\n",[80,225,227],{"id":226},"solution-drop-the-function-and-trigger","Solution: Drop the Function and Trigger",[15,229,230],{},"Run these queries to remove the conflicting function and trigger:",[232,233,235],"h4",{"id":234},"drop-the-function","Drop the Function:",[85,237,239],{"className":144,"code":238,"language":146,"meta":94,"style":94},"DROP FUNCTION IF EXISTS public.handle_new_user();\n",[92,240,241],{"__ignoreMap":94},[150,242,243],{"class":152,"line":153},[150,244,238],{},[232,246,248],{"id":247},"drop-the-trigger","Drop the Trigger:",[85,250,252],{"className":144,"code":251,"language":146,"meta":94,"style":94},"DROP TRIGGER IF EXISTS on_auth_user_created ON auth.users;\n",[92,253,254],{"__ignoreMap":94},[150,255,256],{"class":152,"line":153},[150,257,251],{},[15,259,260],{},"By removing conflicting functions and triggers, you can resolve potential conflicts and retest your database setup.",[39,262,264],{"id":263},"step-4-recreate-the-profiles-table-if-needed","Step 4: Recreate the Profiles Table (If Needed)",[15,266,267,268,271],{},"If the ",[92,269,270],{},"profiles"," table doesn't exist, create it with the correct schema:",[85,273,275],{"className":144,"code":274,"language":146,"meta":94,"style":94},"CREATE TABLE public.profiles (\n  id UUID REFERENCES auth.users ON DELETE CASCADE,\n  full_name TEXT,\n  avatar_url TEXT,\n  created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),\n  updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),\n  PRIMARY KEY (id)\n);\n\n-- Enable Row Level Security\nALTER TABLE public.profiles ENABLE ROW LEVEL SECURITY;\n\n-- Create policies\nCREATE POLICY \"Public profiles are viewable by everyone.\"\n  ON public.profiles FOR SELECT\n  USING (true);\n\nCREATE POLICY \"Users can insert their own profile.\"\n  ON public.profiles FOR INSERT\n  WITH CHECK (auth.uid() = id);\n\nCREATE POLICY \"Users can update own profile.\"\n  ON public.profiles FOR UPDATE\n  USING (auth.uid() = id);\n",[92,276,277,282,287,292,297,302,307,312,317,321,326,331,335,341,347,353,359,364,370,376,382,387,393,399],{"__ignoreMap":94},[150,278,279],{"class":152,"line":153},[150,280,281],{},"CREATE TABLE public.profiles (\n",[150,283,284],{"class":152,"line":159},[150,285,286],{},"  id UUID REFERENCES auth.users ON DELETE CASCADE,\n",[150,288,289],{"class":152,"line":165},[150,290,291],{},"  full_name TEXT,\n",[150,293,294],{"class":152,"line":171},[150,295,296],{},"  avatar_url TEXT,\n",[150,298,299],{"class":152,"line":177},[150,300,301],{},"  created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),\n",[150,303,304],{"class":152,"line":183},[150,305,306],{},"  updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),\n",[150,308,309],{"class":152,"line":189},[150,310,311],{},"  PRIMARY KEY (id)\n",[150,313,314],{"class":152,"line":195},[150,315,316],{},");\n",[150,318,319],{"class":152,"line":201},[150,320,205],{"emptyLinePlaceholder":204},[150,322,323],{"class":152,"line":208},[150,324,325],{},"-- Enable Row Level Security\n",[150,327,328],{"class":152,"line":214},[150,329,330],{},"ALTER TABLE public.profiles ENABLE ROW LEVEL SECURITY;\n",[150,332,333],{"class":152,"line":220},[150,334,205],{"emptyLinePlaceholder":204},[150,336,338],{"class":152,"line":337},13,[150,339,340],{},"-- Create policies\n",[150,342,344],{"class":152,"line":343},14,[150,345,346],{},"CREATE POLICY \"Public profiles are viewable by everyone.\"\n",[150,348,350],{"class":152,"line":349},15,[150,351,352],{},"  ON public.profiles FOR SELECT\n",[150,354,356],{"class":152,"line":355},16,[150,357,358],{},"  USING (true);\n",[150,360,362],{"class":152,"line":361},17,[150,363,205],{"emptyLinePlaceholder":204},[150,365,367],{"class":152,"line":366},18,[150,368,369],{},"CREATE POLICY \"Users can insert their own profile.\"\n",[150,371,373],{"class":152,"line":372},19,[150,374,375],{},"  ON public.profiles FOR INSERT\n",[150,377,379],{"class":152,"line":378},20,[150,380,381],{},"  WITH CHECK (auth.uid() = id);\n",[150,383,385],{"class":152,"line":384},21,[150,386,205],{"emptyLinePlaceholder":204},[150,388,390],{"class":152,"line":389},22,[150,391,392],{},"CREATE POLICY \"Users can update own profile.\"\n",[150,394,396],{"class":152,"line":395},23,[150,397,398],{},"  ON public.profiles FOR UPDATE\n",[150,400,402],{"class":152,"line":401},24,[150,403,404],{},"  USING (auth.uid() = id);\n",[39,406,408],{"id":407},"step-5-test-user-creation","Step 5: Test User Creation",[15,410,411],{},"After completing the above steps:",[47,413,414,417,420],{},[50,415,416],{},"Try creating a new user through Supabase Auth",[50,418,419],{},"Check if the profile is automatically created",[50,421,422],{},"Verify that invite links are sent successfully",[39,424,426],{"id":425},"result","Result",[15,428,429],{},"After all these steps, I was able to:",[15,431,432,433,436,437,439],{},"✅ Create new users successfully",[434,435],"br",{},"\n✅ Send invite links without errors",[434,438],{},"\n✅ Properly manage user profiles in Supabase",[39,441,443],{"id":442},"key-takeaways","Key Takeaways",[47,445,446,453,459,465,471],{},[50,447,448,449,452],{},"✅ ",[26,450,451],{},"Always check Supabase logs"," for detailed error messages",[50,454,448,455,458],{},[26,456,457],{},"Review SQL functions and triggers"," for conflicts",[50,460,448,461,464],{},[26,462,463],{},"Drop and recreate problematic functions"," when necessary",[50,466,448,467,470],{},[26,468,469],{},"Ensure the profiles table exists"," with correct schema",[50,472,448,473,476],{},[26,474,475],{},"Test thoroughly"," after making changes",[39,478,480],{"id":479},"common-causes-of-this-error","Common Causes of This Error",[482,483,484,491,494,500,503],"ul",{},[50,485,486,487,490],{},"Missing ",[92,488,489],{},"public.profiles"," table",[50,492,493],{},"Incorrect function or trigger syntax",[50,495,496,497],{},"Conflicting triggers on ",[92,498,499],{},"auth.users",[50,501,502],{},"Schema migration issues",[50,504,505],{},"Incorrect Row Level Security (RLS) policies",[39,507,509],{"id":508},"related-errors","Related Errors",[15,511,512],{},"This guide also helps with:",[482,514,515,520,525,530],{},[50,516,517],{},[92,518,519],{},"Database error saving new user",[50,521,522],{},[92,523,524],{},"Failed to invite user: failed to make invite request",[50,526,527],{},[92,528,529],{},"relation \"public.profiles\" does not exist",[50,531,532],{},[92,533,534],{},"function public.handle_new_user() does not exist",[536,537],"hr",{},[15,539,540],{},"I hope this post will be helpful to you too.",[15,542,543],{},"Happy coding! 🚀",[39,545,547],{"id":546},"additional-resources","Additional Resources",[482,549,550,559,566],{},[50,551,552],{},[553,554,558],"a",{"href":555,"rel":556},"https://supabase.com/docs/guides/auth",[557],"nofollow","Supabase Auth Documentation",[50,560,561],{},[553,562,565],{"href":563,"rel":564},"https://www.postgresql.org/docs/current/sql-createtrigger.html",[557],"PostgreSQL Triggers",[50,567,568],{},[553,569,572],{"href":570,"rel":571},"https://supabase.com/docs/guides/auth/row-level-security",[557],"Supabase Row Level Security",[15,574,575],{},"Have you encountered similar Supabase errors? Share your experience in the comments below! 💬",[577,578,579],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":94,"searchDepth":159,"depth":159,"links":581},[582,585,586,590,591,592,593,594,595,596],{"id":41,"depth":159,"text":42,"children":583},[584],{"id":82,"depth":165,"text":83},{"id":97,"depth":159,"text":98},{"id":126,"depth":159,"text":127,"children":587},[588,589],{"id":140,"depth":165,"text":141},{"id":226,"depth":165,"text":227},{"id":263,"depth":159,"text":264},{"id":407,"depth":159,"text":408},{"id":425,"depth":159,"text":426},{"id":442,"depth":159,"text":443},{"id":479,"depth":159,"text":480},{"id":508,"depth":159,"text":509},{"id":546,"depth":159,"text":547},"Fix the 'Database error saving new user', 'relation public.profiles does not exist' and 'Failed to invite user' errors in Supabase. Complete step-by-step guide for auth and PostgreSQL profile table issues.","md",{"author":600,"date":601,"image":21,"category":602,"tags":603,"featured":618,"draft":618},"Aysegul Karadan","2023-09-29T10:00:00.000+03:00","Web Development",[604,605,606,607,608,609,610,611,612,613,614,615,616,617],"supabase","nuxt3","database","troubleshooting","postgresql","authentication","supabase-error-fix","profiles-table-error","database-error-saving-new-user","relation-does-not-exist-supabase","supabase-auth-fix","failed-to-invite-user-supabase","supabase-postgresql-error","how-to-fix-supabase-auth-error",false,"/blog/supabase-database-error-saving-new-user",{"title":5,"description":597},{"loc":619},"blog/supabase-database-error-saving-new-user","_YzfRTHId-z7Wzpl2yff4z98XPqjOdth1QaFpjoklAQ",1782986782635]