© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•13mo ago•
1 reply
RUNNb

Constraint does not exist when running migration

This is happening because one of my tables was looking like this:
export const profiles = pgTable('profiles', {
  userId: uuid('user_id').references(() => users.id, { onDelete: 'cascade' });
... rest of the columns
});
export const profiles = pgTable('profiles', {
  userId: uuid('user_id').references(() => users.id, { onDelete: 'cascade' });
... rest of the columns
});


Then on a new migration I've added the onUpdate

export const profiles = pgTable('profiles', {
  userId: uuid('user_id').references(() => users.id, { onDelete: 'cascade', onUpdate: 'cascade' });
... rest of the columns
});
export const profiles = pgTable('profiles', {
  userId: uuid('user_id').references(() => users.id, { onDelete: 'cascade', onUpdate: 'cascade' });
... rest of the columns
});


This change made the migration file to have to alter table to change the constraint

DO $$ BEGIN
 ALTER TABLE "profiles" ADD CONSTRAINT "profiles_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
DO $$ BEGIN
 ALTER TABLE "profiles" ADD CONSTRAINT "profiles_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;


And now when I run this specific migration I'm facing the error:
"Constraint 'profiles_user_id_users_id_fk' of relation "profiles" does not exist"

Any tips how to solve this?
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

column "foo" referenced in foreign key constraint does not exist
Drizzle TeamDTDrizzle Team / help
2y ago
Constraint name in migration not snake case
Drizzle TeamDTDrizzle Team / help
5mo ago
Property does not exist
Drizzle TeamDTDrizzle Team / help
2y ago