Best AI Prompt to Fix "relation does not exist" in Supabase (Error 42P01)
relation "public.todos" does not exist means your app asked for a table the database cannot find. Either the table was never created, its name is spelled or capitalised differently, it lives in another schema, or your app is connected to a different Supabase project.
4 min read

Quick answer: relation "public.todos" does not exist means your app asked for a table the database cannot find. Either the table was never created, its name is spelled or capitalised differently, it lives in another schema, or your app is connected to a different Supabase project. Run the query below to see which.
"Relation" is the Postgres word for a table or view. The error code is 42P01. Through the Supabase client you may see its sibling instead: Could not find the table 'public.todos' in the schema cache (code PGRST205). Both have the same causes.
Find the cause with one query
Open the Supabase SQL Editor and run:
select table_schema, table_name
from information_schema.tables
where table_schema not in ('pg_catalog', 'information_schema')
order by table_schema, table_name;
Now compare the result with the name in your error.
What you see
Cause
Go to
The table is not in the list
It was never created
Fix 1
The table is there, in a different project than your app uses
Wrong project
Fix 2
Name differs by capital letters, e.g. Todos vs todos
Case sensitivity
Fix 3
Name differs slightly, e.g. todo vs todos
Typo or plural mismatch
Fix 4
Table is in a schema other than public
Wrong schema
Fix 5
Everything matches exactly
Stale schema cache
Fix 6
Fix 1: The table was never created
This is the top cause in AI-built apps. The tool wrote the code that uses the table and wrote a migration file, but the migration never ran on your database. Find the SQL in supabase/migrations/ in your project, paste it into the SQL Editor and run it. In Lovable, check the chat for a pending "Apply changes" or SQL approval you skipped.
Fix 2: Your app points to a different project
Common after remixing a project or creating a separate production database. Open your host (Vercel, Netlify, Lovable settings) and compare VITE_SUPABASE_URL or NEXT_PUBLIC_SUPABASE_URL with the URL under Project Settings, API in the Supabase project that has the table. If they differ, update the URL and the anon key together, then redeploy.
Fix 3: Capital letters
Postgres lowercases unquoted names. If the table was created as "Todos" with quotes, then from todos fails. Rename it to lowercase once and avoid the problem forever:
alter table public."Todos" rename to todos;
Fix 4: Typo or plural mismatch
AI tools drift between profile and profiles, or user_profiles and profiles, across prompts. Pick the name that exists in the database and search your codebase for every .from('...') call that uses the other one.
Fix 5: Wrong schema
The client only queries public by default. Either move the table:
alter table my_schema.todos set schema public;
or add the schema under Project Settings, API, Exposed schemas and query it with supabase.schema('my_schema').from('todos').
Fix 6: Stale schema cache
You just created the table and the API has not noticed yet. Reload it:
notify pgrst, 'reload schema';
The prompt to give your AI tool
I get: relation "public.todos" does not exist. Do not rename anything in the code yet. List every table name the code references in .from() calls, and list every migration file that creates a table. Tell me which tables are referenced but never created, and give me the SQL to create them.
FAQ
It works locally but not in production. Why? Your local app and your production app use different Supabase projects, and the migrations only ran on one. Run them on the production project.
The error names a table I never asked for. The AI invented a table while adding a feature. Create it using Fix 1, or remove the feature code that calls it.
I see "relation does not exist" inside an RLS policy or function. The policy or function references a table without its schema. Write public.todos instead of todos inside functions.
Does this error mean my data is gone? No. It means the table name was not found. Existing tables and rows are untouched.
Still stuck?
Rayionyx fixes broken AI-built apps. Run the free scan at rayionyx.com, or book the $199 Rescue Audit for a full written report in 24 hours.