Change into the project root, the directory that contains the supabase folder.

Check whether the supabase directory contains the project ref file left by a previous link.

Find the correct project ref in the Supabase dashboard project settings or from the project URL.

Run the link command with that ref from the project root and enter the database password if prompted.

Rerun the command that failed, from the same directory.

If it still fails, confirm you are logged in to the CLI and that the login matches the account that owns the project.

In CI, run the link step in the same job and working directory as the commands that follow it.