Fix Supabase ERROR: 42846: cannot cast type bigint to uuid

Sharing this fix that I found for working with supabase and I believe it is more of a PostgreSQL issue, here are the some details about the error and how to fix it.

The error “ERROR: 42846: cannot cast type bigint to uuid” occurs because PostgreSQL does not know how to implicitly convert an arbitrary bigint value into a valid uuid format. You must provide an explicit USING expression that defines how to generate a valid uuid from the existing bigint data.

ERROR: 42846: cannot cast type bigint to uuid

Solution Steps

  • First, go to the column you are changing from either int, bigint to a uuid type. Edit the column and go under the extra options then remove “Is Identity” checkbox and save.
  • Next to go SQL Editor and run this command
ALTER TABLE public.watches
ALTER COLUMN id SET DATA TYPE uuid
USING uuid_generate_v4();
  • Next, go back to the table and update the column with a default value.

This fixed the issue for me. That’s it.

Leave a Reply

Your email address will not be published. Required fields are marked *