© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
1 reply
Paddy

Make two columns unique (composite primary key)

Hey everyone,

I need to make the
provider_id
provider_id
and
provider_user_id
provider_user_id
to be unique together (composite primary key).

After migration it returns that it is not allowed to have multiple primary keys. But it does seem to be the way Drizzle ORM want it to work, I think.

Anyone in here that encountered this before with TypeScript, Drizzle ORM?

export const oauthAccount = pgTable(
  'oath_account',
  {
    provider_id: text('provider_id').notNull(),
    provider_user_id: text('provider_user_id').notNull(),
    user_id: text('user_id')
      .notNull()
      .references(() => users.id),
  },
  (table) => {
    return {
      pk: primaryKey({
        columns: [table.provider_id, table.provider_user_id],
      }),
    };
  }
);
export const oauthAccount = pgTable(
  'oath_account',
  {
    provider_id: text('provider_id').notNull(),
    provider_user_id: text('provider_user_id').notNull(),
    user_id: text('user_id')
      .notNull()
      .references(() => users.id),
  },
  (table) => {
    return {
      pk: primaryKey({
        columns: [table.provider_id, table.provider_user_id],
      }),
    };
  }
);


Thank you in advance!
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

Composite Primary Key?
Drizzle TeamDTDrizzle Team / help
16mo ago
reference composite primary key
Drizzle TeamDTDrizzle Team / help
3y ago
Composite primary key, multiple primary keys
Drizzle TeamDTDrizzle Team / help
2y ago
Compostie primary key of a composite primary key
Drizzle TeamDTDrizzle Team / help
2y ago