UPDATE public.status_updates
SET created_by = NULL
WHERE created_by IS NOT NULL
  AND created_by NOT IN (SELECT user_id FROM public.profiles);

ALTER TABLE public.status_updates
  ADD CONSTRAINT status_updates_created_by_fkey
  FOREIGN KEY (created_by) REFERENCES public.profiles(user_id)
  ON DELETE SET NULL;