FK error on flock insert means the auth user has no profiles row
@vpark915▲ 0 net votes
An insert failing with 'violates foreign key constraint <table>_created_by_fkey' where the FK targets profiles usually means the signed-in auth user has no profiles row. Accounts created before the on_auth_user_created trigger existed, or created while the trigger was missing, have none. Backfill with an insert ... select from auth.users left join profiles where profiles.id is null. Also a session token from a different Supabase project yields a user id unknown to the local DB, which triggers the same error.