App Finishers

Fix guide · updated 2026-11-17

Supabase "Database error querying schema" (500 at sign-in): find the broken rows and fix them

Database error querying schema · AuthRetryableFetchError 500 · unexpected_failure · converting NULL to string is unsupported

Some of your users can't sign in. Your app shows Database error querying schema, supabase-js reports AuthRetryableFetchError with status 500, and the Network tab shows a 500 on /auth/v1/token. Most of the time, those users were added to auth.users by SQL (a seed script, an import, or an AI tool) instead of through Supabase Auth, and their rows hold an empty value (NULL) where Auth expects text. One SQL statement fixes them all. If every user gets the error at once, look at your disk first (section 5).

What the error means

To sign someone in, Supabase Auth first reads their row from auth.users. Auth reads some of its columns as text and fails on a NULL there. Auth then stops and answers:

500 {"code":500,"error_code":"unexpected_failure","msg":"Database error querying schema","error_id":"…"}

This happens before the password is checked. In our test, the broken account got the same 500 with a wrong password, while an email that doesn't exist got the usual 400 Invalid login credentials. So the message says nothing about the password, and other users' accounts are not affected.

In our test, users created through Auth's API had none of those NULLs. A SQL insert that leaves four columns out does: confirmation_token, recovery_token, email_change_token_new and email_change have no default value, so they stay NULL. In our test, the usual seed insert (email, crypt() password, email_confirmed_at, metadata, no token columns) gave exactly those four.

1. Find the real error

The app only gets the 500. The reason is in the logs. Make a sign-in fail once more, then open them:

The failed sign-in's line ends with the real reason. In our test we got one of three:

error finding user: sql: Scan error on column index 3, name "confirmation_token": converting NULL to string is unsupported

A NULL in a text column: sections 2 to 4. The column named may differ, the fix is the same.

error locking user: ERROR: cannot execute SELECT FOR NO KEY UPDATE in a read-only transaction (SQLSTATE 25006)

Your database is in read-only mode: section 5.

error finding user: ERROR: permission denied for table users (SQLSTATE 42501)

Auth lost its rights on its own table: section 6.

2. Find the broken rows

Eight text columns of auth.users are the ones that end up NULL. In our test, a NULL in any one of them gave this error, each time with that column's name in the log. Run this in the SQL Editor to list the accounts that have at least one:

select id, email, created_at
from auth.users
where confirmation_token is null or recovery_token is null
   or email_change_token_new is null or email_change is null
   or email_change_token_current is null or phone_change is null
   or phone_change_token is null or reauthentication_token is null;

In our test it listed the account made by the seed insert and nothing else. Accounts created through Auth never showed up.

3. Fix them in one statement

Supabase's own troubleshooting page fixes one column at a time (Supabase, "Database error querying schema"). That works, but the next sign-in can then fail on the next column. This covers all eight at once:

update auth.users set
  confirmation_token         = coalesce(confirmation_token, ''),
  recovery_token             = coalesce(recovery_token, ''),
  email_change_token_new     = coalesce(email_change_token_new, ''),
  email_change               = coalesce(email_change, ''),
  email_change_token_current = coalesce(email_change_token_current, ''),
  phone_change               = coalesce(phone_change, ''),
  phone_change_token         = coalesce(phone_change_token, ''),
  reauthentication_token     = coalesce(reauthentication_token, '')
where confirmation_token is null or recovery_token is null
   or email_change_token_new is null or email_change is null
   or email_change_token_current is null or phone_change is null
   or phone_change_token is null or reauthentication_token is null;

It only touches rows that have a NULL, and only those columns. An empty text is what Auth itself stores there. In our test, after it, the query from step 2 returned nothing, the account signed in, and its magic link worked again.

4. What else the same row breaks

With the broken account still in place, our test got these answers:

If you'd rather delete the account than repair it, do it in the SQL Editor: delete from auth.users where id = '…'; worked in our test where deleteUser failed.

Stop it from coming back

Create users through Supabase Auth, from a server with your service role key (never in browser code). This is how our test made the accounts that never broke:

const { error } = await admin.auth.admin.createUser({
  email: 'person@example.com',
  password: 'a-long-password',
  email_confirm: true,
});

If a seed file must use SQL, give those four columns an empty text. In our test, this account signed in with its password:

insert into auth.users (instance_id, id, aud, role, email, encrypted_password, email_confirmed_at,
  raw_app_meta_data, raw_user_meta_data, created_at, updated_at,
  confirmation_token, recovery_token, email_change_token_new, email_change)
values ('00000000-0000-0000-0000-000000000000', gen_random_uuid(), 'authenticated', 'authenticated',
  'person@example.com', crypt('a-long-password', gen_salt('bf')), now(),
  '{"provider":"email","providers":["email"]}', '{}', now(), now(),
  '', '', '', '');

Keep instance_id at all zeros. Auth only looks for users with that value. In our test, an account inserted with a random instance_id got Invalid login credentials with the right password, and a magic link or a sign-up with its email failed with Database error saving new user, because Auth didn't see the account and tried to create a second one. update auth.users set instance_id = '00000000-0000-0000-0000-000000000000' where instance_id <> '00000000-0000-0000-0000-000000000000'; fixed it.

5. Every user gets it, and you changed nothing

Check your disk. When disk use reaches 95%, Supabase puts the database in read-only mode (Supabase docs, read-only mode). A sign-in locks the user's row before it creates the session, and a read-only database refuses that lock. In our test, read-only mode gave Database error querying schema to every account with the right password, while a wrong password still got Invalid login credentials. Sign-up fails at the same time, with Database error saving new user (we tested it for our "Database error granting user" guide). Once read-only mode was off, sign-in worked again. Supabase's page explains how to free space or grow the disk.

6. After restoring a backup or moving a database

permission denied for table users means auth.users now belongs to another role, for example after a dump was restored as postgres. Auth connects as supabase_auth_admin. In our test, giving the table to postgres broke every sign-in with this message, and this brought it back:

alter table auth.users owner to supabase_auth_admin;

On a hosted Supabase project, if the SQL Editor refuses this, ask Supabase support: the auth schema is theirs to manage.

If an AI tool built your app

Give your tool this prompt:

Sign-in to my Supabase app fails with "Database error querying schema" (500). The Auth log says "converting NULL to string is unsupported": some users were inserted into auth.users by SQL and have NULL in text columns. Give me SQL for the Supabase SQL Editor that sets confirmation_token, recovery_token, email_change_token_new, email_change, email_change_token_current, phone_change, phone_change_token and reauthentication_token to '' where they are NULL, in one update. Then change every place in my project that inserts into auth.users with SQL so it creates users with supabase.auth.admin.createUser from server code instead.

Not quite your error?

Still stuck?

Open the Auth log line of one failed sign-in. The text after error finding user: or error locking user: is the real reason. If step 2 lists no account but the line still names a column, find the rows with select id, email from auth.users where <that column> is null; and give that column a value.

Other Supabase problems? See Supabase fixes.