How to fix 42P01: Undefined table in Supabase
PostgreSQL error 42P01 occurs when you query or reference a table that doesn't exist in your database. Fix it by verifying the table name spelling, checking the schema, running migrations, or quoting identifiers for case-sensitive names.
Quick fix
Fixes 42P01: Undefined table
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY table_name;- Verify the table exists in your database
- Check spelling and exact table name
- Push pending migrations
- Check schema and use fully qualified table names
SELECT table_nameFROM information_schema.tablesWHERE table_schema = 'public'ORDER BY table_name;42P01: Undefined table
What this error means
PostgreSQL error code 42P01 is an "undefined_table" error that occurs when your application tries to query or reference a table that doesn't exist in the database. This is a syntax error that prevents the query from executing. The error typically appears with additional context showing which table name PostgreSQL couldn't find. In Supabase, this usually happens when migrations haven't been run, table names are misspelled, or the table exists in a different schema than expected.
Typical symptoms
- Query execution fails with "undefined table" error message
- Application crashes when trying to access specific tables
- Newly created migrations don't take effect immediately
- Table operations work in Supabase Dashboard but fail in application code
- Case-sensitive table names fail when referenced without quotes
Common causes
- Table doesn't exist yet or migrations haven't been deployed
- Table name is misspelled in the query (typo or casing issue)
- Table exists in a different schema than the one being queried
- PostgreSQL lowercases unquoted identifiers, causing case-sensitive name mismatches
- Connection is to the wrong database or project
How to fix "42P01: Undefined table"
Open Supabase Dashboard and navigate to the SQL Editor. Run this query to list all tables in the public schema:
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY table_name;Check if your table name appears in the results. If it doesn't, the table doesn't exist yet.
Carefully compare the table name in your error message with the actual table name in your database. PostgreSQL is case-sensitive for quoted identifiers:
- If your table is named users (lowercase), reference it as users
- If your table is named "Users" (quoted), you must always use quotes: SELECT * FROM "Users"
- Without quotes, PostgreSQL converts to lowercase: Users becomes users
Check your schema or migrations file for the exact table definition.
If you recently created migrations, they may not have been deployed yet. Use Supabase CLI to push migrations:
supabase db pushIf using the dashboard only, migrations are applied immediately. If using Supabase CLI locally, you must explicitly push them to your project with the command above. Verify the migration succeeded by checking the tables again.
If your table is in a schema other than public, you must specify the schema:
SELECT * FROM your_schema.your_table;View all schemas:
SELECT schema_name
FROM information_schema.schemata;For Supabase Auth tables, use the auth schema:
SELECT * FROM auth.users;If your table name has uppercase letters, you must quote it every time:
// Incorrect - will fail if table is "UserProfiles"
const { data } = await supabase
.from('UserProfiles')
.select()
// Correct - use double quotes to preserve case
const { data } = await supabase
.rpc('your_function', {})
// Or use all lowercase and create table as lowercase
const { data } = await supabase
.from('user_profiles')
.select()Best practice: Always create tables with lowercase names using underscores (snake_case) to avoid quoting issues.
Sometimes a table exists but Row Level Security (RLS) policies prevent you from seeing it. Check RLS settings:
1. Go to Supabase Dashboard > Authentication > Policies
2. Select your table from the dropdown
3. Verify policies allow SELECT access for your user role
If no policies exist, RLS may be disabled (which is fine). If policies exist but don't grant access, add a policy:
CREATE POLICY "Allow public select" ON your_table
FOR SELECT USING (true);Advanced notes
In development, test table creation thoroughly before deploying. If using Supabase CLI with migrations, the local database and remote database must stay in sync—run supabase db push after creating migrations locally. For applications using ORMs like Prisma, ensure migrations are generated and migrations are run: prisma migrate deploy. When working with multiple environments (dev, staging, production), verify you're connected to the correct database URL. Case sensitivity issues are common when migrating from other databases that don't enforce case rules; always use lowercase snake_case for PostgreSQL table names. If you see this error intermittently, it may indicate a connection or caching issue—try restarting your application.
Frequently asked questions
- What does "42P01: Undefined table" mean?
- PostgreSQL error code 42P01 is an "undefined_table" error that occurs when your application tries to query or reference a table that doesn't exist in the database. This is a syntax error that prevents the query from executing. The error typically appears with additional context showing which table name PostgreSQL couldn't find.
- How do I fix "42P01: Undefined table"?
- PostgreSQL error 42P01 occurs when you query or reference a table that doesn't exist in your database. Fix it by verifying the table name spelling, checking the schema, running migrations, or quoting identifiers for case-sensitive names.
- What causes "42P01: Undefined table"?
- Table doesn't exist yet or migrations haven't been deployed Table name is misspelled in the query (typo or casing issue) Table exists in a different schema than the one being queried
- Is the "42P01: Undefined table" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- 📚Supabase Official Documentation
- 📖PostgreSQL Error Codes - 42P01(Official Docs)
- 📖Supabase - Connecting to PostgreSQL(Official Docs)
- 📖Supabase - Database Tables(Official Docs)
- 📖Supabase CLI - Local Development(Official Docs)